https://leetcode.com/problems/binary-tree-coloring-game Solution Time Complexity: O(len(tree)) Space Complexity: O(len(tree)) (The input and output generally do not count towards the space complexity. ...
https://leetcode.com/problems/perfect-squares Solution 問題所求的是合成數字 n 所需 perfect square 最小數量 故,此題 dp[l] := l 個 perfect square 能合成出來的數 = [e + ps for e in dp[l – 1] for ps in pss] pss := [1, 4, 9, ...
https://leetcode.com/problems/find-all-anagrams-in-a-string Solution: Sliding Window with HashMap Time Complexity: O(len(s)) Space Complexity: O(len(p)) (The input and output generally do not count to ...
https://leetcode.com/problems/word-break Solution dp[i] := ∃ j < i s.t. dp[j] == True and s[j:i] in words dp[0] := True n := len(s) m := len(wordDict) k := max([len(w) for w in wordDict]) Time Comp ...
https://leetcode.com/problems/minimum-size-subarray-sum Solution: Sliding Window Time Complexity: O(len(nums)) Space Complexity: O(1) (The input and output generally do not count towards the space com ...
https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii My Solution Time Complexity: O(len(nums)) Space Complexity: O(1) (The input and output generally do not count towards the space com ...
https://leetcode.com/problems/remove-duplicates-from-sorted-array Solution 重點:nums sorted in non-decreasing order Time Complexity: O(len(nums)) Space Complexity: O(1) (The input and output generally d ...
In-Place Algorithm In computer science, an in-place algorithm is an algorithm that operates directly on the input data structure without requiring extra space proportional to the input size. In other ...
https://leetcode.com/problems/longest-substring-without-repeating-characters Solution: Sliding Window Time Complexity: O(len(s)) Space Complexity: O(26) = O(1) (26 lowercase letters) (The input and ou ...
Two Pointers 收縮型 One Input, Opposite Ends (相反的兩端:[left → … ← right]) left 和 right 兩個 pointer 為 opposite ends (相反的兩端;起始於起點和終點,並越來越靠近) Template def fn(arr): ans = 0 left, right = 0, len(arr) - 1 w ...