题解 | #判断字符是否唯一#
判断字符是否唯一
https://www.nowcoder.com/practice/fb08c63e2c4f4f7dbf41086e46044211
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return bool布尔型 */ bool isUnique(string str) { // write code here int cnt[52]={0}; //a~z 26~51 str[] 97 str[i] - 65 97-?=26, 97-71 //A~Z 0~25 str[] 65 str[i]-65 for(int i=0; i<=str.size()-1; i++){ if(str[i]>='a' && str[i] <= 'z'){ cnt[str[i]-71]++; } if(str[i]>='A' && str[i] <= 'Z'){ cnt[str[i]-65]++; } } for(int i=0; i<52; i++){ if(cnt[i] >1){ return false; } } return true; } };