-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPairSum1.java
More file actions
29 lines (26 loc) · 719 Bytes
/
Copy pathPairSum1.java
File metadata and controls
29 lines (26 loc) · 719 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
//brute force
import java.util.ArrayList;
import java.util.*;
public class PairSum1{
public static boolean isPresent(ArrayList<Integer> list, int target){
for(int i=0; i<list.size(); i++){
for(int j=i+1; j<list.size(); j++){
if(list.get(i) + list.get(j) == target){
return true;
}
}
}
return false;
}
public static void main(String args[]){
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);
int target = 50;
System.out.println(isPresent(list,target));
}
}