随笔分类 - Leetcode
Leetcode: Minimum Domino Rotations For Equal Row
摘要:1. The final uniform character should be either A[0] or B[0] 2. A[0] could be at the top, or the bottom. Same applies to B[0] 3. If A[0] works, no nee
阅读全文
Leetcode: Longest Common Subsequence
摘要:DP with a 2D array Time & space: O(m * n) (Skim through) memory optimization, referencing: https://leetcode.com/problems/longest-common-subsequence/di
阅读全文
Leetcode: Encode and Decode TinyURL
摘要:1. 根据系统设计的Estimation of the amount of data we need to store for the next couple of years, 我们应需要6位Base62的char来encode 2. assume 避免地址爆炸,相同的longUrl得到相同的sh
阅读全文
Leetcode: The Maze III(Unsolved Lock Problem)
摘要:Each time, first add the direction to the path, and then go with that direction, checking for hole along the way. When hit a wall, try to turn, and go
阅读全文
Leetcode: The Maze II
摘要:Solution of The Maze: https://discuss.leetcode.com/topic/77471/easy-understanding-java-bfs-solutionSolution of The Maze III: https://discuss.leetcode.
阅读全文
Leetcode: The Maze(Unsolved locked problem)
摘要:Search in the four possible directions when coming to a stopping point (i.e. a new starting point). Keep track of places that you already started at i
阅读全文
Leetcode: Max Consecutive Ones II(unsolved locked problem)
摘要:未研究: The idea is to keep a window [l, h] that contains at most k zero The following solution does not handle follow-up, because nums[l] will need to a
阅读全文
Leetcode: Find Permutation(Unsolve lock problem)
摘要:还没研究: For example, given IDIIDD we start with sorted sequence 1234567Then for each k continuous D starting at index i we need to reverse [i, i+k] port
阅读全文
Leetcode: Sliding Window Median
摘要:方法1:Time Complexity O(NK) 暂时只有两个Heap的做法,缺点:In this problem, it is necessary to be able remove elements that are not necessarily at the top of the heap
阅读全文
Leetcode: Number Complement
摘要:Better solution: Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int va
阅读全文
Leetcode: LFU Cache && Summary of various Sets: HashSet, TreeSet, LinkedHashSet
摘要:referred to: https://discuss.leetcode.com/topic/69137/java-o-1-accept-solution-using-hashmap-doublelinkedlist-and-linkedhashset Two HashMaps are used,
阅读全文
Leetcode: Poor Pigs
摘要:My binary encoding method gives a 8 for the first problem, however, there is a smarter method that generates a answer of 5, which can be found here: h
阅读全文
Leetcode: Validate IP Address
摘要:Be careful, split() will not include trailing empty strings in the result array The string "boo:and:foo", for example, split(":")的结果是 {“boo”, "and", "
阅读全文
Leetcode: Encode String with Shortest Length && G面经
摘要:DP: Initially I think of 1D DP, dp[i] stands for the shortest string of first i characters, then: dp[i] = minLen{dp[k] + encode(substring(k+1, i))} th
阅读全文
Leetcode: Concatenated Words
摘要:Scan through array and DP: We iterate through each word and see if it can be formed by using other words. The subproblem is Word Break I. But it is a
阅读全文
Leetcode: Convex Polygon
摘要:https://discuss.leetcode.com/topic/70706/beyond-my-knowledge-java-solution-with-in-line-explanation https://discuss.leetcode.com/topic/70664/c-7-line-
阅读全文
Leetcode: Unique Substrings in Wraparound String
摘要:这道题我一开始发现了数学规律: length of consecutive chars vs number of different substring “a” -> 1 = 1 "ab" -> 3 = 1+2 "abc" -> 6 = 1+2+3 "abcd" -> 10 = 1+2+3+4 于是
阅读全文
浙公网安备 33010602011771号