Skip to content

Commit 2237ea5

Browse files
committed
update
1 parent 76c7bf8 commit 2237ea5

File tree

2 files changed

+33
-47
lines changed

2 files changed

+33
-47
lines changed

src/main/java/com/leetcode/hash/HashOne.java

-47
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.leetcode.hash;
2+
3+
/**
4+
* two sum
5+
* arr = [2 , 7, 9 , 11 ] , target number 9
6+
* arr[0] + arr[1] = 9
7+
*/
8+
9+
public class TwoSum {
10+
11+
public int[] twoSum(int[] nums, int target) {
12+
for(int i = 0 ; i < nums.length - 1 ; i ++){
13+
for (int j = i + 1 ; j < nums.length ; j ++){
14+
int sum = nums[i] + nums[j];
15+
if(sum == target){
16+
return new int[]{i , j};
17+
}
18+
}
19+
}
20+
return null;
21+
}
22+
23+
public static void main(String[] args) {
24+
int target = 9;
25+
int[] arr = {2, 7, 9, 11};
26+
int[] ints = new TwoSum().twoSum(arr, target);
27+
for(int i : ints){
28+
System.out.println(i);
29+
}
30+
}
31+
}
32+
33+

0 commit comments

Comments
 (0)