Monday, 2 September 2013

how space complexity of this code is O(n)?

how space complexity of this code is O(n)?

public static boolean isUniqueChars2(String str) {
boolean[] char_set = new boolean[256];
for (int i = 0; i < str.length(); i++) {
int val = str.charAt(i);
if (char_set[val]) return false;
char_set[val] = true;
}
return true;
}

No comments:

Post a Comment