Leetcode 389 Solution

This article provides solution to leetcode question 389 (find-the-difference)

https://leetcode.com/problems/find-the-difference

Solution

class Solution {
public:
    char findTheDifference(string s, string t) {
        std::vector<char> vs(s.begin(), s.end());
        std::vector<char> vt(t.begin(), t.end());

        std::sort(vs.begin(), vs.end());
        std::sort(vt.begin(), vt.end());

        for (int i = 0; i < vs.size(); i++)
        {
            if (vs[i] != vt[i])
                return vt[i];
        }

        return *vt.rbegin();
    }
};