algorithm

문제 https://leetcode.com/problems/best-time-to-buy-and-sell-stock/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: prices = [7,1,5,3,6,4] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell. Example 2: Input: prices = [7,6,4,3,1] Outpu..
문제 https://leetcode.com/problems/rotate-array/ 더보기 Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: nums = [-1,-100,3,99], k = 2 Output: [3,99,-1,-100] Explanation: rotate 1 steps to the right: [99,-1,-100,3] ..
문제 https://leetcode.com/problems/valid-anagram/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: s = "anagram", t = "nagaram" Output: true Example 2: Input: s = "rat", t = "car" Output: false Contraints: 1
문제 https://leetcode.com/problems/ransom-note/ 더보기 Example 1: Input: ransomNote = "a", magazine = "b" Output: false Example 2: Input: ransomNote = "aa", magazine = "ab" Output: false Example 3: Input: ransomNote = "aa", magazine = "aab" Output: true Constraints: 1
문제 https://leetcode.com/problems/contains-duplicate-ii/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: nums = [1,2,3,1], k = 3 Output: true Example 2: Input: nums = [1,0,1,1], k = 1 Output: true Example 3: Input: nums = [1,2,3,1,2,3], k = 2 Output: false Contraints: 1
문제 https://leetcode.com/problems/two-sum/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. Example 2: Input: nums = [3,2,4], target = 6 Output: [1,2] Example 3: Input: nums = [3,3], target = 6 Output: [0,1] Contraints: 2
문제 https://leetcode.com/problems/evaluate-reverse-polish-notation/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: tokens = ["2","1","+","3","*"] Output: 9 Explanation: ((2 + 1) * 3) = 9 Example 2: Input: tokens = ["4","13","5","/","+"] Output: 6 Explanation: (4 + (13 / 5)) = 6 Example 3: Input: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"] Output: 22 Exp..
문제 https://leetcode.com/problems/min-stack/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]] Output [null,null,null,null,-3,null,0,-2] Explanation MinStack minStack = new MinStack(); minStack.push(-2); minStack.push(0); minStack.push(-3); minStack.getMin(); // return -3 minStack.pop()..
문제 https://leetcode.com/problems/majority-element/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] Output: 2 ✔ 문제접근 #1 해시테이블[통과] ⭕ Intuition 각 요소값이 등장하는 횟수를 해시테이블을 통하여 관리해준다. Algorithm 배열을 순회하며 각 요소가 등장하는 횟수를 count라는 dict 자료구조에 기록해준다.초기값은 배열의 첫번째 값의 등장횟수 1을 최대라고 생각하고 시작한다. 등장 횟수를 기록해주면서 동시에 현재까지 가장 많이 등장한 횟수의 최..
문제 https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/?envType=study-plan-v2&envId=top-interview-150 더보기 Example 1: Input: nums = [1,1,1,2,2,3] Output: 5, nums = [1,1,2,2,3,_] Explanation: Your function should return k = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively. It does not matter what you leave beyond the returned k (hence they are underscore..
Don't stop 훈
'algorithm' 카테고리의 글 목록 (3 Page)