Design These problems may require you to implement a given interface of a class, and may involve using one or more data structures. These are great exercises to improve your data structure skills. We recommend: Serialize and Deserialize Binary Tree and Insert Delete GetRandom O(1) Flatten 2D Vector Serialize and Deserialize Binary Tree Insert Delete GetRandom O(1) Design Tic-Tac-Toe 251. Flatten..
leetcode.com/problems/jump-game/solution/ 내 답이 솔루션이랑 좀 다르네.. 솔루션 시간내서 읽어보자 class Solution: def canJump(self, nums: List[int]) -> bool: n = len(nums) i = 0 next_dest = 1 + i + nums[i] while i = n else False leetcode.com/problems/unique-paths/solution/ 솔루션에는 2d dp가 있네. 나는 1d dp로 함. 그리고 솔루션에는 math도 있..
leetcode.com/problems/letter-combinations-of-a-phone-number/ leetcode.com/problems/generate-parentheses/ leetcode.com/problems/permutations/ leetcode.com/problems/subsets/solution/ leetcode.com/problems/word-search/solution/
Trees and Graphs 트리는 특별한 유형의 그래프이므로 그래프를 가로 지르는 데 사용되는 두 가지 일반적인 기술도 트리에 적용 할 수 있습니다. 권장 사항 : 이진 트리 순서 순회, 각 노드 및 아일랜드 수에서 다음 오른쪽 포인터 채우기. 일부 트리 문제는 n 진 트리 형식으로도 질문 할 수 있으므로 n 진 트리가 무엇인지 알아야합니다. 참고 : Number of Islands는 트리 문제는 아니지만 그래프로 표시 할 수 있으므로 그래프 문제로 분류합니다. Tree is a special type of graphs, so the two usual techniques used to traverse a graph are also applicable to trees. We recommend: Bina..
leetcode.com/problems/add-two-numbers/ 더미헤드를 하나 만들어서, 더미헤드의 다음부터 맨뒷자리 부터 더하고, 마지막에 캐리가 있으면 하나 더 추가해줌 class Solution: def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: dummy_head = ListNode(0) curr = dummy_head carry = 0 while l1 or l2: x = l1.val if l1 else 0 y = l2.val if l2 else 0 sum = carry + x + y carry = sum // 10 curr.next = ListNode(sum % 10) curr = curr.next if l1: l1 = l..
Array and Strings 인터뷰에서 배열 및 문자열 유형의 질문이 자주 제기되었습니다. 인터뷰 중에 만날 가능성이 큽니다. 권장 사항 : 그룹 아나그램, 반복 문자가없는 가장 긴 부분 문자열, 가장 긴 회문 부분 문자열 및 누락 된 범위. Array and String type of questions were asked in interviews frequently. You will most likely encounter one during your interviews. We recommend: Group Anagrams, Longest Substring Without Repeating Characters, Longest Palindromic Substring and Missing Ranges. 3..
leetcode.com/problems/climbing-stairs/ 다른풀이도 많이 있지만, dp만 찍고 넘어감 dp배열의 인덱스에 주의하자. - 배열크기 n+1 - 시작부분 셋팅 - 루프 인덱스 class Solution: def climbStairs(self, n: int) -> int: if n == 1: return 1 dp = [0 for i in range(n+1)] dp[1] = 1 dp[2] = 2 for i in range(3, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n] leetcode.com/problems/best-time-to-buy-and-sell-stock/ 문제가 쉬운것 같지만, 아직도 설계를 버벅인다. class Solution: def..
88. Merge Sorted Array Easy 32104857Add to ListShare Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is equal to m + n) to hold additional elements from nums2. Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,..
leetcode.com/problems/maximum-depth-of-binary-tree/ class Solution: def maxDepth(self, root: TreeNode) -> int: if root is None: return 0 return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1 class Solution: def maxDepth(self, root: TreeNode) -> int: stack = [] if root is not None: stack.append((1, root)) depth = 0 while stack != []: current_depth, root = stack.pop() if root is not ..
Linked List Linked List problems are relatively easy to master. Do not forget the Two-pointer technique, which not only applicable to Array problems but also Linked List problems as well. Another technique to greatly simplify coding in linked list problems is the dummy node trick. We recommend: Reverse Linked List, Merge Two Sorted Lists Linked List Cycle. For additional challenge, solve these p..
leetcode.com/problems/smallest-range-ii/ 910. Smallest Range II Medium 431186Add to ListShare Given an array A of integers, for each integer A[i] we need to choose either x = -K or x = K, and add x to A[i] (only once). After this process, we have some array B. Return the smallest possible difference between the maximum value of B and the minimum value of B. Example 1: Input: A = [1], K = 0 Outpu..
내용 및 해설 정리: inner-game.tistory.com/46 leetcode.com/problems/reverse-string/ class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ left, right = 0, len(s) - 1 while left < right: s[left], s[right] = s[right], s[left] left, right = left + 1, right - 1 leetcode.com/problems/reverse-integer/ class Solution: def reverse(self, x: int)..
leetcode.com/problems/decoded-string-at-index/ An encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken: If the character read is a letter, that letter is written onto the tape. If the character read is a digit (say d), the entire current tape is repeatedly written d-1 more times in total. N..
Array - Top Interview Questions[EASY] (1/9) : Java 전반적인 해설은 여기에 있음(Java) : inner-game.tistory.com/38 leetcode.com/problems/remove-duplicates-from-sorted-array/ class Solution: def removeDuplicates(self, nums: List[int]) -> int: len_ = 1 if len(nums) == 0: return 0 for i in range(1, len(nums)): if nums[i] != nums[i-1]: nums[len_] = nums[i] len_ += 1 return len_ leetcode.com/problems/best-time-to-..
64. Minimum Path Sum leetcode.com/problems/minimum-path-sum/ Summary We have to find the minimum sum of numbers over a path from the top left to the bottom right of the given matrix . Solution Approach 1: Brute Force The Brute Force approach involves recursion. For each element, we consider two paths, rightwards and downwards and find the minimum sum out of those two. It specifies whether we nee..
1. Two Sum leetcode.com/problems/two-sum/ class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: d = {} for i, n in enumerate(nums): m = target - n if m in d: return [d[m], i] else: d[n] = i class Solution: def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ h = {} for i, num in enumerate(nums): n = target - num if n not in h: h..
leetcode.com/problems/squares-of-a-sorted-array/ 3번으로 해야함. Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2: Input: nums = [-7,-3,2..
leetcode.com/problems/plus-one-linked-list/ Given a non-negative integer represented as a linked list of digits, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list. Example 1: Input: head = [1,2,3] Output: [1,2,4] Example 2: Input: head = [0] Output: [1] Constraints: The number of nodes in the linked list is in the range [1, 100]. 0
leetcode.com/contest/weekly-contest-219 leetcode.com/problems/count-of-matches-in-tournament/ class Solution { public int numberOfMatches(int n) { int round = 0; while(n != 1) { round += n/2; n = n/2+n%2; } return round; } } 빵터짐 ㅋㅋ leetcode.com/problems/count-of-matches-in-tournament/ class Solution { public int minPartitions(String n) { int maximum = 0; for(int i = 0; i < n.length(); i++) { max..
leetcode.com/problems/palindrome-partitioning/ 백트랙킹과 리스트 구성 및 리턴 방식을 눈여겨 볼만한 문제. 시리즈 문제도 같이 풀어보자: inner-game.tistory.com/458 131. Palindrome Partitioning Medium 257384Add to ListShare Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. A palindrome string is a string that reads the same backward as forward. E..
Binary Indexed Tree 프리퀀시 정렬 이지가 하나도 없네 #TitleTagsAcceptanceDifficultyFrequency 315 Count of Smaller Numbers After Self Binary SearchDivide and ConquerSortBinary Indexed TreeSegment TreeGoogle 42.4% Hard 493 Reverse Pairs Binary SearchDivide and ConquerSortBinary Indexed TreeSegment TreeGoogle 26.2% Hard 218 The Skyline Problem Divide and ConquerHeapBinary Indexed TreeSegment TreeLine SweepGoogle..
frequency 로 정렬함 843 Guess the Word Minimax Google 46.4% 913 Cat and Mouse Breadth-first Search Minimax Google 33.8% 486 Predict the Winner Dynamic Programming Minimax Google 48.4% 877 Stone Game Math Dynamic Programming Minimax 66.1% 292 Nim Game Brainteaser Minimax Adobe 54.9% 375 Guess Number Higher or Lower II Dynamic Programming Minimax Google 41.6% 464 Can I Win Dynamic Programming Minimax ..
leetcode.com/problems/burst-balloons/ 312. Burst Balloons Hard 297379Add to ListShare Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and ..
877 Stone Game 66.1% Math, DP, MiniMax 1140 Stone Game II 64.9% DP 1406 Stone Game III 56.9% DP 1510 Stone Game IV 58.6% DP 1563 Stone Game V 40.1% DP 1686 Stone Game VI 38.5% Greedy leetcode.com/problems/stone-game/ 877. Stone Game leetcode.com/problems/stone-game-ii/ 1140. Stone Game II leetcode.com/problems/stone-game-iii/ 1406. Stone Game III leetcode.com/problems/stone-game-iv/ 1510. Stone ..
leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/ Medium 1013272Add to ListShare Given the root of a binary tree, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all the deepest nodes in the original tree. A node is called the deepest if it has the largest depth possible among any node in the entire tree. The subtree..
leetcode.com/contest/biweekly-contest-41 1684. Count the Number of Consistent Strings https://leetcode.com/problems/count-the-number-of-consistent-strings/ 굳이 set 까지 쓸 필요 있을까? class Solution { public int countConsistentStrings(String allowed, String[] words) { boolean[] flag = new boolean[26]; int cnt = 0; for(char ch : allowed.toCharArray()) flag[ch-'a'] = true; for(String word : words) { boole..
leetcode.com/contest/weekly-contest-214 Contest - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 두문제는 합쳐서 30분안에 풀수있었으나 그 다음 두문제 너무 어려웠다. leetcode.com/problems/sell-diminishing-valued-colored-balls/ Sell Diminishing-Valued Colored Balls - LeetCode Level up your coding skills and qu..
leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 2번 방법으로 풀어야함. Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) extra memory. Clarification: Confused why the returned value is an integer, but y..
리트코드 미로찾기 maze 총정리 leetcode.com/problemset/all/?search=maze leetcode.com/problems/the-maze/ 490. The Maze Medium 920104Add to ListShare There is a ball in a maze with empty spaces (represented as 0) and walls (represented as 1). The ball can go through the empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the nex..