File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,8 @@ class Solution {
69
69
70
70
** 题目代码:**
71
71
72
+ Java Code:
73
+
72
74
``` java
73
75
class Solution {
74
76
public int [] twoSum (int [] nums , int target ) {
@@ -88,5 +90,37 @@ class Solution {
88
90
}
89
91
```
90
92
93
+ C++ Code:
94
+
95
+ ``` cpp
96
+ class Solution {
97
+ public:
98
+ vector<int > twoSum(vector<int >& nums, int target) {
99
+ unordered_map<int, int> m;
100
+ for (int i = 0; i < nums.size(); ++i) {
101
+ int t = target - nums[ i] ;
102
+ if (m.count(t)) return { m[ t] , i };
103
+ m[ A[ i]] = i;
104
+ }
105
+ return {};
106
+ }
107
+ };
108
+ ```
109
+
110
+ JS Code:
111
+
112
+ ```js
113
+ const twoSum = function (nums, target) {
114
+ const map = new Map();
115
+ for (let i = 0; i < nums.length; i++) {
116
+ const diff = target - nums[i];
117
+ if (map.has(diff)) {
118
+ return [map.get(diff), i];
119
+ }
120
+ map.set(nums[i], i);
121
+ }
122
+ };
123
+ ```
124
+
91
125
92
126
You can’t perform that action at this time.
0 commit comments