mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-24 10:14:44 +08:00
1. Add the building util of Python
for the markdown docs. 2. Update the deploy.sh
This commit is contained in:
20
docs/chapter_computational_complexity/space_time_tradeoff.md
Normal file → Executable file
20
docs/chapter_computational_complexity/space_time_tradeoff.md
Normal file → Executable file
@ -70,14 +70,7 @@ comments: true
|
||||
=== "Python"
|
||||
|
||||
```python title="leetcode_two_sum.py"
|
||||
class SolutionBruteForce:
|
||||
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
||||
# 两层循环,时间复杂度 O(n^2)
|
||||
for i in range(len(nums) - 1):
|
||||
for j in range(i + 1, len(nums)):
|
||||
if nums[i] + nums[j] == target:
|
||||
return i, j
|
||||
return []
|
||||
[class]{SolutionBruteForce}-[func]{}
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
@ -247,16 +240,7 @@ comments: true
|
||||
=== "Python"
|
||||
|
||||
```python title="leetcode_two_sum.py"
|
||||
class SolutionHashMap:
|
||||
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
||||
# 辅助哈希表,空间复杂度 O(n)
|
||||
dic = {}
|
||||
# 单层循环,时间复杂度 O(n)
|
||||
for i in range(len(nums)):
|
||||
if target - nums[i] in dic:
|
||||
return dic[target - nums[i]], i
|
||||
dic[nums[i]] = i
|
||||
return []
|
||||
[class]{SolutionHashMap}-[func]{}
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
|
Reference in New Issue
Block a user