본문 바로가기

전체 글

[Leetcode/파이썬] 64. Minimum Path Sum Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any point in time. Example 1:Input: grid = [[1,3,1],[1,5,1],[4,2,1]]Output: 7Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.Example 2:Input: grid = [[1,2,3],[4,5,6]].. 더보기
[Leetcode/파이썬] Insert Delete GetRandom O(1) Insert Delete GetRandom O(1)Implement the RandomizedSet class:RandomizedSet() Initializes the RandomizedSet object.bool insert(int val) Inserts an item val into the set if not present. Returns true if the item was not present, false otherwise.bool remove(int val) Removes an item val from the set if present. Returns true if the item was present, false otherwise.int getRandom() Returns a random el.. 더보기
[Leetcode/파이썬] 452. Minimum Number of Arrows to Burst Balloons Minimum Number of Arrows to Burst BalloonsThere are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons.Arrows can be shot up directly vertically (.. 더보기
[Leetcode/파이썬] 208. Implement Trie (Prefix Tree) Implement Trie (Prefix Tree)A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.Implement the Trie class:Trie() Initializes the trie object.void insert(String word) Inserts the string word into the trie.boolean search(S.. 더보기
[Leetcode/파이썬] 101. Symmetric Tree Symmetric TreeGiven the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1:Input: root = [1,2,2,3,4,4,3]Output: trueExample 2:Input: root = [1,2,2,null,3,null,3]Output: false Constraints:The number of nodes in the tree is in the range [1, 1000].-100 Follow up: Could you solve it both recursively and iteratively? # Definition for a binary.. 더보기
[Leetcode/파이썬] 155. Min Stack Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the MinStack class:MinStack() initializes the stack object.void push(int val) pushes the element val onto the stack.void pop() removes the element on the top of the stack.int top() gets the top element of the stack.int getMin() retrieves the minimum element in the stack.You must im.. 더보기
[Leetcode/파이썬] 433. Minimum Genetic Mutation Minimum Genetic MutationA gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'.Suppose we need to investigate a mutation from a gene string startGene to a gene string endGene where one mutation is defined as one single character changed in the gene string.For example, "AACCGGTT" --> "AACCGGTA" is one mutation.There is also a gene bank bank that r.. 더보기
[Leetcode/파이썬] 198.House Robber House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.Given an integer array nums representing the amou.. 더보기