Easy-18

xiaoxiao2021-02-27  877

leetcode    389. Find the Difference  

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.

        

AC:

char findTheDifference(char* s, char* t) {     int len1=strlen(s);     int len2=strlen(t);     int num=0;     char c;     for(int i=0;i<len1;i++)     {         num+=t[i]-s[i];     }     for(int i=len1;i<len2;i++)     {         num+=t[i];     }     c=num;     return c; }

转载请注明原文地址: https://www.6miu.com/read-31.html

最新回复(0)