-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPairSum2.java
More file actions
30 lines (26 loc) · 735 Bytes
/
Copy pathPairSum2.java
File metadata and controls
30 lines (26 loc) · 735 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
//Brute force approach
import java.util.ArrayList;
import java.util.*;
public class PairSum2{
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(11);
list.add(15);
list.add(6);
list.add(8);
list.add(9);
list.add(10);
int target = 155;
System.out.println(isPresent(list, target));
}
}