Leetcode # 213. House Robber II
https://leetcode.com/problems/house-robber-ii Solution _rob() := 必定搶最後一間的收益 結果 := max(搶最後一間, 不搶最後一間) = max(搶最後一間 and 不搶第一間, 不搶最後一間) = max(_rob(nums[1:]), robs(nums[:-1])) Time Complexity: O ...
https://leetcode.com/problems/house-robber-ii Solution _rob() := 必定搶最後一間的收益 結果 := max(搶最後一間, 不搶最後一間) = max(搶最後一間 and 不搶第一間, 不搶最後一間) = max(_rob(nums[1:]), robs(nums[:-1])) Time Complexity: O ...
https://leetcode.com/problems/delete-and-earn Solution Time Complexity: O(len(nums)) Space Complexity: O(len(counter)) (The input and output generally do not count towards the space complexity.) class ...
https://leetcode.com/problems/n-th-tribonacci-number Solution Time Complexity: O(n) Space Complexity: O(n) (The input and output generally do not count towards the space complexity.) class Solution: d ...
https://leetcode.com/contest/biweekly-contest-110/problems/minimum-seconds-to-equalize-a-circular-array/ Solution 解這題的心路歷程 找平均值 ⇒ [8,13,3,3] → 找眾數.⇒ [1,11,11,11,19,12,8,7,19] → 接觸到鄰居最多的數 ⇒ [8,14,10,6 ...
Ctrl + a 移動到行首 Ctrl + e 移動到行尾
echo $SHELL ⇒ /bin/zsh nano ~/.zshrc export PATH=${PATH}:...新的路徑... 重新開機 或 source .zshrc
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 ...