Skip to content

Commit bb63a6c

Browse files
committed
Started CTCI
Signed-off-by: mayur3086 <mayurkulkarni012@gmail.com>
1 parent e5a1e3d commit bb63a6c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

CTCI/Chapter1.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package CTCI;
2+
3+
import java.util.BitSet;
4+
import java.util.Scanner;
5+
6+
7+
/**
8+
* @author Mayur Kulkarni <mayurkulkarni012@gmail.com>
9+
*/
10+
public class Chapter1 {
11+
12+
public static void isUnique(String input) {
13+
BitSet mask = new BitSet();
14+
boolean isUnique = true;
15+
for (char i : input.toCharArray()) {
16+
int ascii = (int) i;
17+
if (mask.get(ascii)) {
18+
System.out.println("Duplicate char: " + i);
19+
isUnique = false;
20+
} else {
21+
mask.set(ascii);
22+
}
23+
}
24+
if (isUnique) System.out.println("Is Unique!");
25+
}
26+
27+
public static void main(String[] args) {
28+
Scanner in = new Scanner(System.in);
29+
String inp = in.next();
30+
isUnique(inp);
31+
}
32+
}

0 commit comments

Comments
 (0)