MCPcopy Create free account
hub / github.com/careercup/ctci / isUniqueChars2

Method isUniqueChars2

java/Chapter 1/Question1_1/Question.java:18–29  ·  view source on GitHub ↗
(String str)

Source from the content-addressed store, hash-verified

16 }
17
18 public static boolean isUniqueChars2(String str) {
19 if (str.length() > 128) {
20 return false;
21 }
22 boolean[] char_set = new boolean[128];
23 for (int i = 0; i < str.length(); i++) {
24 int val = str.charAt(i);
25 if (char_set[val]) return false;
26 char_set[val] = true;
27 }
28 return true;
29 }
30
31 public static void main(String[] args) {
32 String[] words = {"abcde", "hello", "apple", "kite", "padle"};

Callers 1

mainMethod · 0.95

Calls 1

lengthMethod · 0.45

Tested by

no test coverage detected