实现一个算法确定字符串中的字符是否均唯一出现
样例
给出"abc"
,返回 true
给出"aab"
,返回 false
public class Solution {
/**
* @param str: a string
* @return: a boolean
*/
public boolean isUnique(String str) {
// write your code here
if(str.length()==0)
return false;
Set<Character> set=new HashSet<Character>();
for(int i=0;i<str.length();i++){
set.add(str.charAt(i));
}
if(set.size()==str.length())
return true;
return false;
}
}