C++,
time: O(n^2)
space: O(0)
class Solution {
public:
/**
* @param str: a string
* @return: a boolean
*/
bool isUnique(string &str) {
// write your code here
for (int i=; i<str.size(); i++) {
for (int j=i+; j<str.size(); j++) {
if (str[i] == str[j]) {
return false;
}
}
}
return true;
}
};
C++,
time: O(n)
space: O(n)
class Solution {
public:
/**
* @param str: a string
* @return: a boolean
*/
bool isUnique(string &str) {
// write your code here
string tmp;
for (int i=; i<str.size(); i++) {
if (- == tmp.find(str[i])) {
tmp.push_back(str[i]);
} else {
return false;
}
}
return true;
}
};