[Python] assert 斷言
- 2025.01.05
- assert statement
assert expression[, arguments] ≡ if not expression: raise AssertionError[(arguments)]
assert expression[, arguments] ≡ if not expression: raise AssertionError[(arguments)]
單行 <span style="color: #CF4D72; background-color: #f7f7f7; border: 1px #DEDEDE solid;"> ... </span> 多行 <div style="color: #CF4D72; background-color: #f7f7f7; border: 1px #DEDEDE s ...
asyncio: Library for writing concurrent code. async / await 3.5 版前async def函數內無法使用yield或 yield from 會引發SyntaxError錯誤 3.6 版以後有了 Asynchronous Generators 而可以使用yield 使用例 import asyncio import time ...
Problem https://leetcode.com/problems/target-sum First Try [Time Limit Exceeded 124 / 140 testcases passed] Time Complexity: O(2 ** len(nums)) Space Complexity: O(2 ** len(nums)) (The input and outpu ...
Problem https://leetcode.com/problems/find-largest-value-in-each-tree-row Solution: BFS Time Complexity: O(len(tree)) Space Complexity: O(log(len(tree))) (The input and output generally do not count t ...
Problem https://leetcode.com/problems/find-building-where-alice-and-bob-can-meet Given a, b If a == b, let k = a = b If heights[max(a, b)] > heights[min(a, b)] ⇒ ans = max(a, b) K = set([k for k in ...
親孝—行って何?って考—える でもそれを考—えようとすることがもう 親孝—行なのかもしれない 子供の頃 たまに家族で 外食 いつも頼んでいたのは チキンライス 豪華なもの頼めば二度とつれてきては もらえ—な—いよう—な気—がして 親に気を遣って いたあんな気持ち 今の子供に 理解—できるかな—? 今日は—クリスマス 街はにぎやか お祭り騒ぎ— 七面—鳥は やっぱり照れる— 俺は まだまだチキンライ ...
Problem https://leetcode.com/problems/reverse-odd-levels-of-binary-tree Solution Time Complexity: O(len(tree)) Space Complexity: O(len(tree)) (The input and output generally do not count towards the s ...
Problem https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone Solution Time Complexity: O(len(seats) * log(len(seats))) Space Complexity: O(len(seats)) (The input and output generally ...
Problem https://leetcode.com/problems/max-chunks-to-make-sorted 把 arr 分成數個 chunk, [sorted(chunk) for chunk in chunks] == sorted(arr) Solution: PrefixMax and SuffixMin Arrays prefix := arr[0 : i] suffi ...