Skip to content

Instantly share code, notes, and snippets.

@akashkumarcs19
Created January 29, 2021 11:23
Show Gist options
  • Save akashkumarcs19/712b2fdf4c6dcfb341988d80139c8998 to your computer and use it in GitHub Desktop.
Save akashkumarcs19/712b2fdf4c6dcfb341988d80139c8998 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
import java.util.Map;
class Question2 {
public static final int MAX_UNICODE = 65_535;
public static void main(String[] args) {
System.out.println(checkWhetherStringIsUnique("Competitive Programming"));
}
public static boolean checkWhetherStringIsUnique(String string) {
Map<Character, Integer> characters = new HashMap<>();
// Write your code here...
char[] c = string.toCharArray();
char[] temp = c;
for (int i = 0; i < c.length; i++) {
int count = 0;
if (characters.containsKey(c[i])) {
count = characters.get(c[i]);
characters.put(c[i], ++count);
}
}
for (int i : characters.values()) {
if (i > 1)
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment