- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1980.java
36 lines (34 loc) · 1.12 KB
/
_1980.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
26
27
28
29
30
31
32
33
34
35
36
packagecom.fishercoder.solutions.secondthousand;
importjava.util.Arrays;
importjava.util.HashSet;
importjava.util.Set;
publicclass_1980 {
publicstaticclassSolution1 {
publicStringfindDifferentBinaryString(String[] nums) {
Set<String> set = newHashSet<>(Arrays.asList(nums));
intlen = nums[0].length();
StringBuildersb = newStringBuilder();
inti = 0;
while (i < len) {
sb.append(1);
i++;
}
intmax = Integer.parseInt(sb.toString(), 2);
for (intnum = 0; num <= max; num++) {
Stringbinary = Integer.toBinaryString(num);
if (binary.length() < len) {
sb.setLength(0);
sb.append(binary);
while (sb.length() < len) {
sb.insert(0, "0");
}
binary = sb.toString();
}
if (!set.contains(binary)) {
returnbinary;
}
}
returnnull;
}
}
}