LeetCode

LeetCode

[LeetCode] 121. Best Time to Buy and Sell Stock

Best Time to Buy and Sell Stock - LeetCode Can you solve this real interview question? Best Time to Buy and Sell Stock - You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosin leetcode.com 날짜별 주식가격이 주어지고 주식가격을 특정일에 사서 특정일에 판다고 가정했을때 가장 큰 수익을 냈을경우 그 수익을 구하는 문제입니다. 수익을 내지 못할경..

LeetCode

[LeetCode] 189. Rotate Array

Rotate Array - LeetCode Can you solve this real interview question? Rotate Array - Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 step leetcode.com 배열을 돌리는 문제입니다. 처음에 단순히 or문을 2번 사용하면 되겠다고 생각했습니다. 즉, k번만큼 loop를 돌면서 nums를 다시 loop 탐색하여 값을 돌리는 것입니다. 하지만, 이 로..

LeetCode

[LeetCode] 169. Majority Element

Majority Element - LeetCode Can you solve this real interview question? Majority Element - Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists leetcode.com 크기가 n인 int배열 이 주어지면 majority element를 반환합니다. majority element는 ⌊n / 2⌋ 이상 나타나는 요소입니다. majority element가 항..

LeetCode

[LeetCode] 80. Remove Duplicates from Sorted Array II

Remove Duplicates from Sorted Array II - LeetCode Can you solve this real interview question? Remove Duplicates from Sorted Array II - Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place [https://en.wikipedia.org/wiki/In-place_algorithm] such that each unique elemen leetcode.com int 배열이 주어지면 최대 2개까지의 중복만 허용하여 배열을 재구성하는 문제입니다. 추가적인 메모리 할당은 O(1)만 허용됩니다. 입출력 ..

Sol b
'LeetCode' 카테고리의 글 목록 (9 Page)