Skip to content

Commit f7da884

Browse files
committed
2018/04/12
1 parent f0284f5 commit f7da884

9 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.idea
2+
*.class
3+
target
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package leetcode;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* @author Kyle
7+
* @create 2018/4/12 2:45
8+
*/
9+
public class Main {
10+
public static void main(String[] args) {
11+
TwoSum twoSum = new TwoSum();
12+
int nums[] = {3, 2, 3};
13+
int target = 6;
14+
System.out.println(Arrays.toString(twoSum.twoSum(nums, target)));
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package leetcode;
2+
3+
/**
4+
* @author Kyle
5+
* @create 2018/4/12 2:44
6+
*/
7+
public class TwoSum {
8+
public int[] twoSum(int[] nums, int target) {
9+
int[] result = new int[2];
10+
11+
int length = nums.length;
12+
for(int i = 0; i < length - 1; i++) {
13+
for(int j = i + 1; j < length; j++) {
14+
if(nums[i] + nums[j] == target) {
15+
result[0] = i;
16+
result[1] = j;
17+
break;
18+
}
19+
}
20+
}
21+
return result;
22+
}
23+
}

0 commit comments

Comments
 (0)