https://leetcode.com/problems/single-number/ XOR \begin{align} 1. \, & p \oplus 0 = p \\ 2. \, & p \oplus p = 0 \\ 3. \, & 有交換律: p \oplus q = q \oplus p \\ & \Rightarrow p \oplus q \o ...
Bitwise(位元運算) a & b Bitwise AND a | b Bitwise OR a ^ b Bitwise XOR (exclusive OR) ~a Bitwise NOT a << n Bitwise left shift a >> n Bitwise right shift 相關例題 Leetcode # 190. Reverse Bits ...
iterator 有__next__()以取得 iterator 的下一個item 有__iter__():return self generator 屬於 iterator,但反之則不成立 使用yield表達式實作__next__()
https://leetcode.com/problems/letter-case-permutation/ Solution Time Complexity = Space Complexity = O(len(s) * 2 ^ len(s)) class Solution: def letterCasePermutation(self, s: str) -> List[str]: f = ...
Brute-Force(暴力法 / 窮舉法) 列出所有可能的解答候選,再保留那些通過驗證的解答候選 例題 Backtracking(回溯法) Brute-Force 的一種 嘗試分步的解決問題 當現在這一步不符合條件時 ⇒ 退回上一步 經常使用遞迴 (recursion) 來實現 backtracking Difference with Dynamic Programing backtrackin ...
https://leetcode.com/problems/squares-of-a-sorted-array/ First Solution 注意 nums 僅有負數的場合! Time Complexity: O(len(nums)) Space Complexity: O(1) (The input and output generally do not count towards the s ...
https://leetcode.com/problems/search-insert-position/ Solution Time Complexity: O(log(len(nums))) Space Complexity: O(1) class Solution: def searchInsert(self, nums: List[int], target: int) -> int: ...
發聲練習1 肩膀環繞至後方 兩掌互推並與胸口保持一段不小的距離, 雙臂將肋骨往左右撐開 下半身箭步(一前一後)深蹲 隨著發聲慢慢更下沉 發聲練習2 肩膀環繞至後方, 雙手向前伸但不往上,使胸口向內縮 背部肩胛骨向外綣起 雙手做抱蛋狀 雙腳與肩同寬 足弓成弓狀,腳趾與腳跟穩穩抓住地面 屁股向後,尾椎至頭部呈一直線
https://leetcode.com/problems/contains-duplicate/ Solution Sorting Time Complexity: O(n * log(n)) Space Complexity: O(1) with heap sort Worst case space complexity is O(n) and best case O(1) with sort ...
https://leetcode.com/problems/first-bad-version/ Solution Time Complexity: O(log(n)) Space Complexity: O(1) class Solution: def firstBadVersion(self, n: int) -> int: if isBadVersion(1): return 1 go ...