mirror of
https://github.com/SunnyQjm/algorithm-homework.git
synced 2026-10-05 01:15:36 +08:00
add:homework4
This commit is contained in:
1 parent
b51d6cca9e
commit
762309f24c
8 files changed
+161
-21
No files matched your search
@@ -7,11 +7,14 @@
|
||||
3道上课讲的LeetCode题目1,69,70
|
||||
|
||||
- ## Leetcode problem 1 (两数之和)
|
||||
- 算法思路:<br/>
|
||||
用字典记录数字,以便在找到成对的另一个数的时候,可以快速的检索到前一个数的索引
|
||||
|
||||
- 算法思路:
|
||||
|
||||
用字典记录数字,以便在找到成对的另一个数的时候,可以快速的检索到前一个数的索引
|
||||
|
||||
- Leetcode提交结果
|
||||

|
||||
|
||||
- 代码:
|
||||
```python
|
||||
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
||||
@@ -19,10 +22,10 @@
|
||||
for index, num in enumerate(nums):
|
||||
if num in myDict:
|
||||
return [myDict[num], index]
|
||||
else:
|
||||
else:
|
||||
myDict[target - num] = index
|
||||
```
|
||||
|
||||
|
||||
- ## Leetcode problem 69 (x 的平方根)
|
||||
- 算法思路:二分法
|
||||
|
||||
|
||||
Reference in new issue
Block a user