문제풀이
Leetcode First Unique Character in a String JAVA
by AndoneKwon
2020. 12. 25.
class Solution {
public int firstUniqChar(String s) {
char[] allChar = s.toCharArray();
Map<Character,Integer> map = new HashMap<>();
char uniqueChar;
int answer=-1;
if(allChar.length==1){
return 0;
}
for(int i=0;i<allChar.length;i++){
uniqueChar=allChar[i];
answer = i;
if(map.get(uniqueChar)!=null){
answer = -1;
continue;
}
for(int j=i+1;j<allChar.length;j++){
if(uniqueChar==allChar[j]){
map.put(uniqueChar,1);
answer=-1;
break;
}
}
if(answer!=-1){
break;
}
}
return answer;
}
}