-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwoSum.java
25 lines (21 loc) · 875 Bytes
/
twoSum.java
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
//package com.pluralsight.calcengine;
import java.util.*;
class twoSum {
public static void main(String[] args) {
int[] arr= new int[]{3, 5, -4, 8, 11, 1, -1, 6};
int target=10;
//Integer target=Integer.parseInt(args[args.length-1]);
// public static int[] twoSum (int[] nums, int target){
for (int i = 0; i < arr.length; i++) {
System.out.println("array no " + i + " is " + arr[i]);
for (int j = i + 1; j < arr.length; j++) {
System.out.println("loop(j) " + j + " is " + arr[j]);
if (arr[j] == target - arr[i]) {
System.out.println("i =:" +i +"j=:"+j);
// return new int[]{i, j};
}
}
}
// throw new IllegalArgumentException("No two sum solution");
}
}