File tree 3 files changed +37
-0
lines changed
solution/0100-0199/0167.Two Sum II - Input array is sorted
3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,20 @@ class Solution {
96
96
}
97
97
```
98
98
99
+ ### ** TypeScript**
100
+
101
+ ``` ts
102
+ function twoSum(numbers : number [], target : number ): number [] {
103
+ for (let right = numbers .length - 1 ; right >= 0 ; -- right ) {
104
+ let left = numbers .indexOf (target - numbers [right ]);
105
+ if (left > - 1 && left < right ) {
106
+ return [left + 1 , right + 1 ];
107
+ }
108
+ }
109
+ return [- 1 , - 1 ];
110
+ };
111
+ ```
112
+
99
113
### ** C++**
100
114
101
115
``` cpp
Original file line number Diff line number Diff line change @@ -85,6 +85,20 @@ class Solution {
85
85
}
86
86
```
87
87
88
+ ### ** TypeScript**
89
+
90
+ ``` ts
91
+ function twoSum(numbers : number [], target : number ): number [] {
92
+ for (let right = numbers .length - 1 ; right >= 0 ; -- right ) {
93
+ let left = numbers .indexOf (target - numbers [right ]);
94
+ if (left > - 1 && left < right ) {
95
+ return [left + 1 , right + 1 ];
96
+ }
97
+ }
98
+ return [- 1 , - 1 ];
99
+ };
100
+ ```
101
+
88
102
### ** C++**
89
103
90
104
``` cpp
Original file line number Diff line number Diff line change
1
+ function twoSum ( numbers : number [ ] , target : number ) : number [ ] {
2
+ for ( let right = numbers . length - 1 ; right >= 0 ; -- right ) {
3
+ let left = numbers . indexOf ( target - numbers [ right ] ) ;
4
+ if ( left > - 1 && left < right ) {
5
+ return [ left + 1 , right + 1 ] ;
6
+ }
7
+ }
8
+ return [ - 1 , - 1 ] ;
9
+ } ;
You can’t perform that action at this time.
0 commit comments