Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe2fe7f

Browse files
feat: adds two sum in nim, minor fix in readme_en (doocs#497)
1 parent ccd6862 commit fe2fe7f

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

‎solution/0000-0099/0001.Two Sum/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ class Solution {
131131
}
132132
```
133133

134+
### **Nim**
135+
136+
```nim
137+
import std/enumerate
138+
139+
proc twoSum(nums: seq[int], target: int): seq[int] =
140+
var
141+
bal: int
142+
tdx: int
143+
for idx, val in enumerate(nums):
144+
bal = target - val
145+
if bal in nums:
146+
tdx = nums.find(bal)
147+
if idx != tdx:
148+
return @[idx, tdx]
149+
150+
```
151+
134152
### **...**
135153

136154
```

‎solution/0000-0099/0001.Two Sum/README_EN.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<pre>
1717
<strong>Input:</strong> nums = [2,7,11,15], target = 9
1818
<strong>Output:</strong> [0,1]
19-
<strong>Output:</strong> Because nums[0] + nums[1] == 9, we return [0, 1].
19+
<strong>Explanation:</strong> Because nums[0] + nums[1] == 9, we return [0, 1].
2020
</pre>
2121

2222
<p><strong>Example 2:</strong></p>
@@ -117,6 +117,24 @@ class Solution {
117117
}
118118
```
119119

120+
### **Nim**
121+
122+
```nim
123+
import std/enumerate
124+
125+
proc twoSum(nums: seq[int], target: int): seq[int] =
126+
var
127+
bal: int
128+
tdx: int
129+
for idx, val in enumerate(nums):
130+
bal = target - val
131+
if bal in nums:
132+
tdx = nums.find(bal)
133+
if idx != tdx:
134+
return @[idx, tdx]
135+
136+
```
137+
120138
### **...**
121139

122140
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#[
2+
Author: @joe733
3+
]#
4+
5+
import std/enumerate
6+
7+
proc twoSum(nums: seq[int], target: int): seq[int] =
8+
var
9+
bal: int
10+
tdx: int
11+
for idx, val in enumerate(nums):
12+
bal = target - val
13+
if bal in nums:
14+
tdx = nums.find(bal)
15+
if idx != tdx:
16+
return @[idx, tdx]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /