forked from architsingla13/InterviewBit-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffk.java
More file actions
39 lines (31 loc) · 716 Bytes
/
Diffk.java
File metadata and controls
39 lines (31 loc) · 716 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
33
34
35
36
37
38
39
package Hashing;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Author - archit.s
* Date - 28/10/18
* Time - 7:09 PM
*/
public class Diffk {
public boolean isDiffPresent(List<Integer> A, int B){
Set<Integer> s = new HashSet<>();
for(int i=0;i<A.size();i++){
int value = A.get(i);
if(s.contains(value)){
return true;
}
else{
s.add(B+value);
s.add(value-B);
}
}
return false;
}
public int diffPossible(final List<Integer> A, int B) {
if(isDiffPresent(A,B)){
return 1;
}
return 0;
}
}