Why is my code wrong? The result is correct on my dev-c++.


  • 0
    K
    class Solution {
    public:
        string removeDuplicateLetters(string s) {
            int count[26]={0};
            string res="";
            for(int i=0;i<s.size();++i){
                count[s[i]-'a']++;
            }
            for(int i=0;i<26;++i){
                if(count[i]!=0){
                    char c=i+'a';
                    res.push_back(c);
                }
            }
            return res;
         }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.