A1go

50/53ページ

Binary Method 二分法

分治法 Divide and Conquer 總是能夠將「問題 X 」拆分為「問題 A 」和「問題 B 」 滿足「問題 A 」+「問題 B 」=「問題 X 」 且能確定「問題 X 」的解只存在於「問題 A 」或「問題 B 」兩者其中之一 如果「問題 X 」的 brute force 解法之 time complexity 為 O(n) 則使用 binary method 的時間複雜度將減少為 O( ...

         続きを読む

Leetcode # 210. Course Schedule II

https://leetcode.com/problems/course-schedule-ii/ Explanation 使用 in-degree 關鍵在於 優先提取 in-degree 為 0 的 vertex(即該 vertex 已無任何前導 vertex) vertex被提取時,調整其子 vertex 的 in-degree 當 graph 中有 loop 當 graph 中有 loop ...

         続きを読む

Leetcode # 143. Reorder List

https://leetcode.com/problems/reorder-list/ Key point 使用一快一慢的pointer來找到length和middle node Solution class Solution: def reorderList(self, head: Optional[ListNode]) -> None: """ Do not return anythin ...

         続きを読む

[Python] Sorting

概覽 Syntax Description Average Time Complexity Space Complexity list_b = sorted(list_a) 回傳排序好的新list O(n * log(n)); n = len(list_a) O(n) list_a.sort() 將list_a排序 O(n * log(n)) O(n) 常用auguments key 排序時以ke ...

         続きを読む
1 ... 50 ... 53
Bitnami