Find the Difference
Input: s = "abcd", t = "abcde"
Output: "e"
Explanation: 'e' is the letter that was added.
Input: s = "", t = "y"
Output: "y"
Input: s = "a", t = "aa"
Output: "a"Solutions
π§ Cpp
Last updated
Input: s = "abcd", t = "abcde"
Output: "e"
Explanation: 'e' is the letter that was added.
Input: s = "", t = "y"
Output: "y"
Input: s = "a", t = "aa"
Output: "a"Last updated
Input: s = "ae", t = "aea"
Output: "a"#define all(x) (x).begin(), (x).end()
class Solution
{
public:
char findTheDifference(string s, string t)
{
std::sort(all(s));
std::sort(all(t));
string diff;
std::set_difference(all(t),
all(s),
back_inserter(diff));
return diff.front();
}
};