实现一个算法,确定一个字符串 s 的所有字符是否全都不同。
示例1
输入:s = "leetcode"
输出:false
示例2
输入:s = "abc"
输出:true
实现代码
public static boolean isUnique(String astr) {
char[] chars = astr.toCharArray();
for (int i = 0; i < chars.length; i++) {
for (int j = i + 1; j < chars.length; j++) {
if(chars[i] == chars[j]) {
return false;
}
}
}
return true;
}