6m C++ using sort


  • 0
    class Solution {
    public:
        char findTheDifference(string s, string t) {
            sort(s.begin(), s.end());
            sort(t.begin(), t.end());
            
            int i = 0;
            
            while(true)
            {
                if(s[i] != t[i])
                {
                    return t[i];
                }
                else if(i+1 > s.length())
                {
                    return t[i+1];
                }
                else
                {
                    i++;
                }
            }
            
            return 0;
        }
    };
    
    

Log in to reply
 

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