Skip to content

Commit 6dc46a5

Browse files
去掉刚刚错误的代码
1 parent 05400ac commit 6dc46a5

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

docs/Leetcode_Solutions/001._two_sum.md

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
lookup {2:0} [0,1]
2727
```
2828

29-
一但字典内有了这个 `target - 当前数字`,找到它的index和当前index一起返回。
30-
29+
* 建立字典 lookup 存放第一个数字,并存放该数字的 index
30+
* 判断 lookup 种是否存在: `target - 当前数字`, 则表面 当前值和 lookup中的值加和为 target.
31+
* 如果存在,则返回: `target - 当前数字` 的 index 和 当前值的 index
3132

3233
```python
3334
class Solution(object):
@@ -44,23 +45,3 @@ class Solution(object):
4445
lookup[num] = i
4546
return []
4647
```
47-
48-
> 思路 2
49-
50-
通过 差值 判断元素,是否存在 nums,存在就 return
51-
52-
```python
53-
class Solution:
54-
def twoSum(self, nums, target):
55-
"""
56-
:type nums: List[int]
57-
:type target: int
58-
:rtype: List[int]
59-
"""
60-
for num in nums:
61-
if num < target:
62-
l1_index = nums.index(num)
63-
l2 = target - num
64-
if l2 in nums:
65-
return [l1_index, nums.index(l2)]
66-
```

0 commit comments

Comments
 (0)