Last active
November 19, 2018 14:57
-
-
Save minikuma/c8639d421b1357afded7ca3f15427969 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
public class UniqueChars { | |
boolean isUniqueChars(String str) { | |
if (str.length() > 128) return false; | |
//미리 선언된 배열 -> 문자 요소가 등장할 때마다 메모하는 용도로 사용 | |
boolean[] char_set = new boolean[128]; | |
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; | |
} | |
//client | |
public static void main(String[] args) { | |
UniqueChars u = new UniqueChars(); | |
System.out.println(u.isUniqueChars("abcd")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment