Skip to content

Commit 242211f

Browse files
refactor 167
1 parent 3696a2b commit 242211f

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/main/java/com/fishercoder/solutions/_167.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
*/
1616

1717
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+
}
3334
}
35+
return new int[] {-1, -1};
3436
}
35-
return new int[]{-1, -1};
3637
}
37-
3838
}

src/test/java/com/fishercoder/_167Test.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
import static org.junit.Assert.assertArrayEquals;
88

99
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;
1313

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+
}
1818

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+
}
2525
}

0 commit comments

Comments
 (0)