File tree 1 file changed +2
-5
lines changed
1 file changed +2
-5
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ class Solution {
36
36
}
37
37
}
38
38
```
39
- javascript
39
+ javascript:
40
40
``` javascript
41
41
var twoSum = function (nums , target ) {
42
42
for (let i = 0 ; i < nums .length - 1 ; i++ ) {
@@ -71,7 +71,7 @@ class Solution {
71
71
## 思路 1
72
72
73
73
利用 HashMap 作为存储,键为目标值减去当前元素值,索引为值,比如 ` i = 0 ` 时,此时首先要判断 ` nums[0] = 2 ` 是否在 map 中,如果不存在,那么插入键值对 ` key = 9 - 2 = 7, value = 0 ` ,之后当 ` i = 1 ` 时,此时判断 ` nums[1] = 7 ` 已存在于 map 中,那么取出该 ` value = 0 ` 作为第一个返回值,当前 ` i ` 作为第二个返回值,具体代码如下所示。
74
-
74
+ java:
75
75
``` java
76
76
class Solution {
77
77
public int [] twoSum (int [] nums , int target ) {
@@ -88,12 +88,9 @@ class Solution {
88
88
}
89
89
```
90
90
91
-
92
91
## 结语
93
92
94
93
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[ LeetCode-Solution] [ ls ]
95
94
96
-
97
-
98
95
[ title ] : https://leetcode.com/problems/two-sum
99
96
[ ls ] : https://github.com/SDE603/LeetCode-Solution
You can’t perform that action at this time.
0 commit comments