Problem https://leetcode.com/problems/take-gifts-from-the-richest-pile Solution Time Complexity: O(len(gifts)) Space Complexity: O(len(gifts)) (The input and output generally do not count towards the ...
Function def function(): ... Method class 底下有 method 和 attribute (屬性), 即 method 便是 class 的 member function (成員函式) class c: def method(): ...
Problem https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation Solution n ∈ nums, you can replace it with any integer from the range [n – k, n + k] ⇒ plus 1 (+1) from ...
Problem https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i Solution / First Try 第 5 行的s + "*"是為了能在結尾時再做一次判斷 aaaaa代表包含 1 個aaaaa, 2 個aaaa, 3 個aaa, 4 個aa, 5 個a Time Complex ...
Problem https://leetcode.com/problems/special-array-ii Solution: Sliding Window 由於從 0 ~ (len(n) – 1) 的所有 indeses 都要建置 所以使用 list 會比 dict 時間上效率更好 第 6 列的nums[1:] + [nums[-1]]是為了檢驗最後一個元素 Time Comple ...
Problem https://leetcode.com/problems/two-best-non-overlapping-events Testcases # Input Expected 1 相關例題 Solution / First Try [Time Limit Exceeded 36 / 63 testcases passed] Time Complexity: O(le ...
Problem https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i Solution Time Complexity: O(max(len(banned), n)) Space Complexity: O(len(banned)) (The input and output genera ...
Problem https://leetcode.com/problems/move-pieces-to-obtain-a-string Solution Time Complexity: O(len(start)) Space Complexity: O(len(start)) (The input and output generally do not count towards the sp ...
Problem https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments Solution 使用try-except避免多次的p1的out of index檢查 Time Complexity: O() Space Complexity: O() (The input and output gen ...
Problem https://leetcode.com/problems/adding-spaces-to-a-string Solution Time Complexity: O(len(s) + len(spaces)) Space Complexity: O(len(s) + len(spaces)) (The input and output generally do not count ...