File tree Expand file tree Collapse file tree 3 files changed +78
-32
lines changed
solution/0000-0099/0001.Two Sum Expand file tree Collapse file tree 3 files changed +78
-32
lines changed Original file line number Diff line number Diff line change @@ -302,22 +302,6 @@ def two_sum(nums, target)
302
302
end
303
303
```
304
304
305
- #### Nim
306
-
307
- ``` nim
308
- import std/enumerate
309
- import std/tables
310
-
311
- proc twoSum(nums: seq[int], target: int): seq[int] =
312
- var d = initTable[int, int]()
313
- for i, x in nums.pairs():
314
- let y = target - x
315
- if d.hasKey(y):
316
- return @[d[y], i]
317
- d[x] = i
318
- return @[]
319
- ```
320
-
321
305
#### Kotlin
322
306
323
307
``` kotlin
@@ -337,6 +321,39 @@ class Solution {
337
321
}
338
322
```
339
323
324
+ #### Cangjie
325
+
326
+ ``` cj
327
+ class Solution {
328
+ func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
329
+ let d = HashMap<Int64, Int64>()
330
+ for (i in 0..nums.size) {
331
+ if (d.contains(target - nums[i])) {
332
+ return [d[target - nums[i]], i]
333
+ }
334
+ d[nums[i]] = i
335
+ }
336
+ []
337
+ }
338
+ }
339
+ ```
340
+
341
+ #### Nim
342
+
343
+ ``` nim
344
+ import std/enumerate
345
+ import std/tables
346
+
347
+ proc twoSum(nums: seq[int], target: int): seq[int] =
348
+ var d = initTable[int, int]()
349
+ for i, x in nums.pairs():
350
+ let y = target - x
351
+ if d.hasKey(y):
352
+ return @[d[y], i]
353
+ d[x] = i
354
+ return @[]
355
+ ```
356
+
340
357
<!-- tabs: end -->
341
358
342
359
<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -299,22 +299,6 @@ def two_sum(nums, target)
299
299
end
300
300
```
301
301
302
- #### Nim
303
-
304
- ``` nim
305
- import std/enumerate
306
- import std/tables
307
-
308
- proc twoSum(nums: seq[int], target: int): seq[int] =
309
- var d = initTable[int, int]()
310
- for i, x in nums.pairs():
311
- let y = target - x
312
- if d.hasKey(y):
313
- return @[d[y], i]
314
- d[x] = i
315
- return @[]
316
- ```
317
-
318
302
#### Kotlin
319
303
320
304
``` kotlin
@@ -334,6 +318,39 @@ class Solution {
334
318
}
335
319
```
336
320
321
+ #### Cangjie
322
+
323
+ ``` cj
324
+ class Solution {
325
+ func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
326
+ let d = HashMap<Int64, Int64>()
327
+ for (i in 0..nums.size) {
328
+ if (d.contains(target - nums[i])) {
329
+ return [d[target - nums[i]], i]
330
+ }
331
+ d[nums[i]] = i
332
+ }
333
+ []
334
+ }
335
+ }
336
+ ```
337
+
338
+ #### Nim
339
+
340
+ ``` nim
341
+ import std/enumerate
342
+ import std/tables
343
+
344
+ proc twoSum(nums: seq[int], target: int): seq[int] =
345
+ var d = initTable[int, int]()
346
+ for i, x in nums.pairs():
347
+ let y = target - x
348
+ if d.hasKey(y):
349
+ return @[d[y], i]
350
+ d[x] = i
351
+ return @[]
352
+ ```
353
+
337
354
<!-- tabs: end -->
338
355
339
356
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ func twoSum(nums: Array<Int64>, target: Int64): Array<Int64> {
3
+ let d = HashMap<Int64, Int64>()
4
+ for (i in 0..nums.size) {
5
+ if (d.contains(target - nums[i])) {
6
+ return [d[target - nums[i]], i]
7
+ }
8
+ d[nums[i]] = i
9
+ }
10
+ []
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments