Skip to content

Commit 878381c

Browse files
add 1980
1 parent deb040b commit 878381c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1980|[Find Unique Binary String](https://leetcode.com/problems/find-unique-binary-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1980.java) ||Medium||
1112
|1979|[Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1979.java) ||Easy||
1213
|1974|[Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1974.java) ||Easy||
1314
|1968|[Array With Elements Not Equal to Average of Neighbors](https://leetcode.com/problems/array-with-elements-not-equal-to-average-of-neighbors/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1968.java) ||Medium||
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
7+
public class _1980 {
8+
public static class Solution1 {
9+
public String findDifferentBinaryString(String[] nums) {
10+
Set<String> set = new HashSet<>(Arrays.asList(nums));
11+
int len = nums[0].length();
12+
StringBuilder sb = new StringBuilder();
13+
int i = 0;
14+
while (i < len) {
15+
sb.append(1);
16+
i++;
17+
}
18+
int max = Integer.parseInt(sb.toString(), 2);
19+
for (int num = 0; num <= max; num++) {
20+
String binary = Integer.toBinaryString(num);
21+
if (binary.length() < len) {
22+
sb.setLength(0);
23+
sb.append(binary);
24+
while (sb.length() < len) {
25+
sb.insert(0, "0");
26+
}
27+
binary = sb.toString();
28+
}
29+
if (!set.contains(binary)) {
30+
return binary;
31+
}
32+
}
33+
return null;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy