版权声明:本文未经博主允许不得转载。 https://blog.csdn.net/pianzang5201/article/details/90575476
问题:
实现一个算法确定字符串中的字符是否均唯一出现
样例:
样例 1:
输入: "abc_____" 输出: false
样例 2:
输入: "abc" 输出: true
python:
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 True
C++:
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;
}
};