【题目】
实现一个算法,确定一个字符串 s 的所有字符是否全都不同。
来源:leetcode
链接:https://leetcode-cn.com/problems/is-unique-lcci/
【示例1】
输入: s = “leetcode”
输出: false
【示例2】
输入: s = “abc”
输出: true
【提示】
0 <= len(s) <= 100
如果你不使用额外的数据结构,会很加分
【代码】
class Solution {
public:
int ch[26]={0};
bool isUnique(string astr) {
for(auto x:astr){
if(ch[x-'a']>=1)
return false;
ch[x-'a']++;
}
return true;
}
};