-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTSMain.java
More file actions
51 lines (49 loc) · 1.45 KB
/
Copy pathTSMain.java
File metadata and controls
51 lines (49 loc) · 1.45 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Solution {
public static int[] twoSum(int[] nums, int target){
for (int i=0; i<nums.length; i++){
for (int j=i+1; j<nums.length; j++){
int result=nums[i]+nums[j];
if (result==target){
return new int[] {i,j};
}
}
}
}
}
public class TSMain{
public static void main(String[] args){
int[] nums={2,7,11,15};
int target=9; //get nums arr and target value from the user
System.out.println("Input: nums = "+nums.toString()+", target = "+target);
System.out.println("Output: "+Solution.twoSum(nums.toString(),target));
}
}
/**
* import java.lang.Object;
class Solution {
public static int[] twoSum(int[] nums, int target){
for (int i=0; i<nums.length; i++){
for (int j=i+1; j<nums.length; j++){
int result=nums[i]+nums[j];
if (result==target){
return new int[] {i,j};
}
}
}
return new int[] {-1,-1};
}
}
public class TSMain{
public static void main(String[] args){
int[] nums={2,7,11,15};
int target=9; //get nums arr and target value from the user
System.out.println("Input: nums = "+nums.toString()+", target = "+target);
System.out.println("Output: "+Solution.twoSum(nums,target));
}
}
Submitted Answer
*/
/**
* Correct answer
*
*/