Created
January 29, 2021 11:23
-
-
Save akashkumarcs19/712b2fdf4c6dcfb341988d80139c8998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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