We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a3d7b57 commit 954babbCopy full SHA for 954babb
two-sum/leebeanbin.java
@@ -0,0 +1,28 @@
1
+import java.util.HashMap;
2
+
3
+public class leebeanbin {
4
+ public static int[] bruteForce(int[] nums, int target) {
5
+ for (int i = 0; i < nums.length; i++) {
6
+ for (int j = i + 1; j < nums.length; j++) {
7
+ if (nums[i] + nums[j] == target) {
8
+ return new int[]{i, j};
9
+ }
10
11
12
+ return null;
13
14
15
+ public static int[] hashMap(int[] nums, int target) {
16
+ HashMap<Integer, Integer> arr = new HashMap<>();
17
18
19
+ arr.put(nums[i], i);
20
21
+ if (arr.containsKey(target - nums[i])) {
22
+ return new int[]{arr.get(target - nums[i]), i};
23
24
25
26
27
28
+}
0 commit comments