@lru_cache[(maxsize=128, typed=False)] least recently used cache(memoize): 會依照 parameters 記錄 return 結果 再次以相同 parameters 呼叫此函式時 將略過計算,直接回傳之前的記錄結果 上限為最近使用的 maxsize 個 若 maxsize 為 None 則無上限 若 typed 為 Tru ...
In C do{ ... } while(condition) In Python while True: ... if not (condition): break
https://leetcode.com/problems/coin-change-ii Solution: Top-Down DP 用 (amount, len(coins)) 作為 self.memo 的key Time Complexity: O(n * amount) Space Complexity: O(n * amount) 1 <= coins[i] <= 5000 n ...
https://leetcode.com/problems/maximal-square Solution square := {top, bottom, left, right} side_length(square) := (bottom – top + 1) == (right – left + 1) dp[i][j] := side length of the ma ...
a > b and b > c→a > b > c
https://leetcode.com/problems/search-in-rotated-sorted-array-ii Solution Leetcode # 33. Search in Rotated Sorted Array 的 solution 配合題目修改了 input 跟 output class Solution: def search(self, nums: List[int ...
https://leetcode.com/problems/minimize-the-maximum-difference-of-pairs Solution: Greedy Method + Binary Search Greedy Method – count_valid_pairs(threshold) count_valid_pairs(threshold): 事先已將num ...
https://leetcode.com/problems/search-in-rotated-sorted-array Solution n := len(nums) nums = [numk, numk+1, …numn-1] + [num0, num1, …, numk-1] = numsA + numsB numi < numj, if i < j; 0 ...
https://leetcode.com/problems/encode-and-decode-strings Solution Time Complexity: O(len(s)) Space Complexity: O(len(strs)) (The input and output generally do not count towards the space complexity.) c ...
https://leetcode.com/problems/longest-common-subsequence Solution: Top-Down DP Time Complexity: O(len(text1) * len(text2)) Space Complexity: O(len(text1) * len(text2)) (The input and output generally ...