题目来源【Leetcode】
Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
Example:
Input:
s = “abcd”
t = “abcde”Output:
eExplanation:
‘e’ is the letter that was added.
这道题就是找出插入的那个字母。我是算出两个字符串的每个字母的和再相减,所得的数再转化为字母输出
class Solution {
public:
char findTheDifference(string s, string t) {
int n = 0;
int m = 0;
for(int i = 0; i < s.length() ; i ++){
n += s[i];
}
for(int i = 0; i < t.length() ; i ++){
m += t[i];
}
cout<<n<<" "<<m<<endl;
return (char)(m-n);
}
};