File tree Expand file tree Collapse file tree 2 files changed +30
-30
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 2 files changed +30
-30
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
17
17
public class _167 {
18
-
19
- public int [] twoSum (int [] numbers , int target ) {
20
- int left = 0 ;
21
- int right = numbers .length - 1 ;
22
- while (left < right ) {
23
- long sum = numbers [left ] + numbers [right ];
24
- if (sum > target ) {
25
- right --;
26
- } else if (sum < target ) {
27
- left ++;
28
- } else {
29
- int [] res = new int [2 ];
30
- res [0 ] = left + 1 ;
31
- res [1 ] = right + 1 ;
32
- return res ;
18
+ public static class Solution1 {
19
+ public int [] twoSum (int [] numbers , int target ) {
20
+ int left = 0 ;
21
+ int right = numbers .length - 1 ;
22
+ while (left < right ) {
23
+ long sum = numbers [left ] + numbers [right ];
24
+ if (sum > target ) {
25
+ right --;
26
+ } else if (sum < target ) {
27
+ left ++;
28
+ } else {
29
+ int [] res = new int [2 ];
30
+ res [0 ] = left + 1 ;
31
+ res [1 ] = right + 1 ;
32
+ return res ;
33
+ }
33
34
}
35
+ return new int [] {-1 , -1 };
34
36
}
35
- return new int []{-1 , -1 };
36
37
}
37
-
38
38
}
Original file line number Diff line number Diff line change 7
7
import static org .junit .Assert .assertArrayEquals ;
8
8
9
9
public class _167Test {
10
- private static _167 test ;
11
- private static int [] numbers ;
12
- private static int [] expected ;
10
+ private static _167 . Solution1 solution1 ;
11
+ private static int [] numbers ;
12
+ private static int [] expected ;
13
13
14
- @ BeforeClass
15
- public static void setup () {
16
- test = new _167 ();
17
- }
14
+ @ BeforeClass
15
+ public static void setup () {
16
+ solution1 = new _167 . Solution1 ();
17
+ }
18
18
19
- @ Test
20
- public void test1 () {
21
- numbers = new int []{-3 , 3 , 4 , 90 };
22
- expected = new int []{1 , 2 };
23
- assertArrayEquals (expected , test .twoSum (numbers , 0 ));
24
- }
19
+ @ Test
20
+ public void test1 () {
21
+ numbers = new int [] {-3 , 3 , 4 , 90 };
22
+ expected = new int [] {1 , 2 };
23
+ assertArrayEquals (expected , solution1 .twoSum (numbers , 0 ));
24
+ }
25
25
}
You can’t perform that action at this time.
0 commit comments