这道题居然做得这么顺利, 果然刷题不能靠体力,要靠脑力!
就是想虽然你顺序不一样,但你值一样的,不就是多一个数吗,分别就和,然后做差,okay了 AC!分分钟搞定
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: e Explanation: 'e' is the letter that was added.
char findTheDifference(char* s, char* t) {
int i=0;
int num1=0,num2=0;
int lens=strlen(s);
int lent=strlen(t);
for(i=0;i<lent;i++){
num1+=s[i];
num2+=t[i];
}
return num2-num1;
}