Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
Example 1:
Input: s
= "leetcode"
Output: false
Example 2:
Input: s
= "abc"
Output: true
Note:
0 <= len(s) <= 100
class Solution:
def isUnique(self, astr: str) -> bool:
sets = set(astr)
return len(sets) == len(astr)
class Solution {
public boolean isUnique(String astr) {
char[] chars = astr.toCharArray();
int len = chars.length;
for (int i = 0; i < len - 1; ++i) {
for (int j = i + 1; j < len; ++j) {
if (chars[i] == chars[j]) {
return false;
}
}
}
return true;
}
}