-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
32 lines (27 loc) · 856 Bytes
/
Solution.java
File metadata and controls
32 lines (27 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class Solution {
public int[] twoSum(int[] nums, int target) {
for(int i=0;i<nums.length;i++){
for(int j =0;j<nums.length;j++){
if(nums[i]+nums[j] == target )
System.out.println(i+" "+j);
}
}
return nums;
}
public static void main(String[] args){
int[] nums = {2,7,11,15};
int target = 9;
Solution so = new Solution();
so.twoSum(nums,target);}
}
//Leetcode practice
//public int[] twoSum(int[] nums, int target) {
// for (int i = 0; i < nums.length; i++) {
// for (int j = i + 1; j < nums.length; j++) {
// if (nums[j] == target - nums[i]) {
// return new int[] { i, j };
// }
// }
// }
// throw new IllegalArgumentException("No two sum solution");
//}