We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2ed040b commit 0a3990aCopy full SHA for 0a3990a
two-sum/dongzoolee.ts
@@ -0,0 +1,20 @@
1
+function twoSum(nums: number[], target: number): number[] {
2
+ const sz = nums.length;
3
+ let l = 0,
4
+ r = 1,
5
+ sm = nums[0] + nums[1];
6
+
7
+ while (l <= sz - 2 && r <= sz - 1) {
8
+ sm = nums[l] + nums[r];
9
10
+ if (sm === target) {
11
+ return [l, r];
12
+ }
13
14
+ if (l === r - 1) {
15
+ (r++, (l = 0));
16
+ } else {
17
+ l++;
18
19
20
+}
0 commit comments