当前位置:网站首页>Interview question 01.01 Determine whether the character is unique

Interview question 01.01 Determine whether the character is unique

2022-07-04 22:02:00 Mr Gao

Interview questions 01.01. Determine whether the character is unique

Implement an algorithm , Determine a string s Whether all the characters of are different .

Example 1:

Input : s = “leetcode”
Output : false

Example 2:

Input : s = “abc”
Output : true

This question is actually relatively simple , The solution code is as follows :

bool isUnique(char* astr){
    
    int r[26];
    int i;
    for(i=0;i<26;i++){
    
        r[i]=0;
    }
    i=0;
    while(astr[i]!='\0'){
    
        r[astr[i]-'a']++;
      // printf("%d",)
        if(r[astr[i]-'a']>=2){
    
            return false;
        }
        i++;
    }
return true;
}
}
原网站

版权声明
本文为[Mr Gao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207042123507763.html