实现一个算法确定字符串中的字符是否均唯一出现
样例 1:
输入: "abc_____" 输出: false样例 2:
输入: "abc" 输出: truepython:
class Solution: """ @param: str: A string @return: a boolean """ def isUnique(self, str): # write your code here for i in range(len(str)): for j in range(i+1, len(str)): if str[i] == str[j]: return False return TrueC++:
class Solution { public: /* * @param str: A string * @return: a boolean */ bool isUnique(string &str) { // write your code here for(int i = 0; i < str.size(); i++) { for(int j = i+1; j < str.size(); j++) { if(str[i] == str[j]) { return false; } } } return true; } };