Skip to content

Commit

Permalink
refactor 167
Browse files Browse the repository at this point in the history
  • Loading branch information
fishercoder1534 committed May 26, 2018
1 parent 3696a2b commit 242211f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
34 changes: 17 additions & 17 deletions src/main/java/com/fishercoder/solutions/_167.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
*/

public class _167 {

public int[] twoSum(int[] numbers, int target) {
int left = 0;
int right = numbers.length - 1;
while (left < right) {
long sum = numbers[left] + numbers[right];
if (sum > target) {
right--;
} else if (sum < target) {
left++;
} else {
int[] res = new int[2];
res[0] = left + 1;
res[1] = right + 1;
return res;
public static class Solution1 {
public int[] twoSum(int[] numbers, int target) {
int left = 0;
int right = numbers.length - 1;
while (left < right) {
long sum = numbers[left] + numbers[right];
if (sum > target) {
right--;
} else if (sum < target) {
left++;
} else {
int[] res = new int[2];
res[0] = left + 1;
res[1] = right + 1;
return res;
}
}
return new int[] {-1, -1};
}
return new int[]{-1, -1};
}

}
26 changes: 13 additions & 13 deletions src/test/java/com/fishercoder/_167Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
import static org.junit.Assert.assertArrayEquals;

public class _167Test {
private static _167 test;
private static int[] numbers;
private static int[] expected;
private static _167.Solution1 solution1;
private static int[] numbers;
private static int[] expected;

@BeforeClass
public static void setup() {
test = new _167();
}
@BeforeClass
public static void setup() {
solution1 = new _167.Solution1();
}

@Test
public void test1() {
numbers = new int[]{-3, 3, 4, 90};
expected = new int[]{1, 2};
assertArrayEquals(expected, test.twoSum(numbers, 0));
}
@Test
public void test1() {
numbers = new int[] {-3, 3, 4, 90};
expected = new int[] {1, 2};
assertArrayEquals(expected, solution1.twoSum(numbers, 0));
}
}

0 comments on commit 242211f

Please sign in to comment.