Skip to content

Commit b06d359

Browse files
committed
format
1 parent 088038a commit b06d359

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

Two Sum.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,44 @@ public int getIndex() {
2222
return index;
2323
}
2424

25-
public void setIndex(int index) {
26-
this.index = index;
27-
}
25+
public void setIndex(int index) {
26+
this.index = index;
27+
}
2828

29-
public int getValue() {
30-
return value;
31-
}
29+
public int getValue() {
30+
return value;
31+
}
3232

33-
public void setValue(int value) {
34-
this.value = value;
35-
}
33+
public void setValue(int value) {
34+
this.value = value;
3635
}
36+
}
3737

38-
public int[] twoSum(int[] numbers, int target) {
39-
Num[] newArray = new Num[numbers.length];
40-
for (int i = 0; i < numbers.length; i++) {
41-
newArray[i] = new Num(numbers[i], i);
38+
public int[] twoSum(int[] numbers, int target) {
39+
Num[] newArray = new Num[numbers.length];
40+
for (int i = 0; i < numbers.length; i++) {
41+
newArray[i] = new Num(numbers[i], i);
4242
}
43-
Arrays.sort(newArray, new Comparator<Num>() {
44-
public int compare(Num n1, Num n2) {
45-
if (n1.getValue() == n2.getValue()) return 0;
46-
if (n1.getValue() > n2.getValue()) return 1;
47-
return -1;
48-
}
49-
});
50-
int[] result = new int[2];
51-
int i = 0, j = numbers.length - 1;
43+
Arrays.sort(newArray, new Comparator<Num>() {
44+
public int compare(Num n1, Num n2) {
45+
if (n1.getValue() == n2.getValue()) return 0;
46+
if (n1.getValue() > n2.getValue()) return 1;
47+
return -1;
48+
}
49+
});
50+
int[] result = new int[2];
51+
int i = 0, j = numbers.length - 1;
5252
while (i < j) {
53-
int tmp = newArray[i].getValue() + newArray[j].getValue();
54-
if (tmp == target) {
55-
result[0] = Math.min(newArray[i].getIndex() + 1, newArray[j].getIndex() + 1);
53+
int tmp = newArray[i].getValue() + newArray[j].getValue();
54+
if (tmp == target) {
55+
result[0] = Math.min(newArray[i].getIndex() + 1, newArray[j].getIndex() + 1);
5656
result[1] = Math.max(newArray[i].getIndex() + 1, newArray[j].getIndex() + 1);
57-
break;
58-
} else if (tmp > target) {
59-
j--;
60-
} else {
61-
i++;
62-
}
57+
break;
58+
} else if (tmp > target) {
59+
j--;
60+
} else {
61+
i++;
62+
}
6363
}
6464
return result;
6565
}

0 commit comments

Comments
 (0)