File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
Algorithms Basics/Chapter 1. Array_String Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -5,22 +5,22 @@ 653. Two Sum IV - Input is a BST
5
5
*/
6
6
public class Solution {
7
7
public int [ ] TwoSum ( int [ ] nums , int target ) {
8
- int [ ] res = null ;
9
- if ( nums == null || nums . Length == 0 ) {
10
- return res ;
8
+ int [ ] result = null ;
9
+ if ( nums == null || nums . Length < 2 ) {
10
+ return result ;
11
11
}
12
12
for ( int i = 0 , j = nums . Length - 1 ; i < j ; ) {
13
- var v = nums [ i ] + nums [ j ] ;
14
- if ( v == target ) {
15
- res = new int [ ] { i + 1 , j + 1 } ;
13
+ var sum = nums [ i ] + nums [ j ] ;
14
+ if ( sum == target ) {
15
+ result = new int [ ] { i + 1 , j + 1 } ;
16
16
break ;
17
17
}
18
- if ( v < target ) {
18
+ if ( sum < target ) {
19
19
i ++ ;
20
20
} else {
21
21
j -- ;
22
22
}
23
23
}
24
- return res ;
24
+ return result ;
25
25
}
26
26
}
You can’t perform that action at this time.
0 commit comments