389. Find the Difference(C语言)

来源:互联网 发布:怎么下载发票软件 编辑:程序博客网 时间:2024/06/14 20:39

这道题居然做得这么顺利, 果然刷题不能靠体力,要靠脑力!

就是想虽然你顺序不一样,但你值一样的,不就是多一个数吗,分别就和,然后做差,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:eExplanation:'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;}


0 0
原创粉丝点击