Find the Difference/solution.c
/*

You are given two strings s and t.

String t is generated by random shuffling string s and then add one more letter at a random position.

Return the letter that was added to t.
From leetcode : https://leetcode.com/problems/find-the-difference/

*/
You are given two strings s and t.
String t is generated by random shuffling string s and then add one more letter at a random position.

Return the letter that was added to t.
You are given two strings s and t . String t is generated by random shuffling string s and then add one more letter at a random position . Return the letter that was added to t .
char findTheDifference(char * s, char * t){
    int i,a[26]={0}; 
    for(i=0;i<strlen(s);i++) 
    {
        a[s[i]-'a']++; 
        a[t[i]-'a']--;
    }
    a[t[i]-'a']--; 
    for(i=0;i<26;i++) {
        if(a[i]==-1) {
            return i + 'a';
        }
    }
    return 0;
}
char findTheDifference ( char * s , char * t ) { int i , a [ 26 ] = { 0 } ; for ( i = 0 ; i < strlen ( s ) ; i ++ ) { a [ s [ i ] - ' ' ] ++ ; a [ t [ i ] - ' ' ] -- ; } a [ t [ i ] - ' ' ] -- ; for ( i = 0 ; i < 26 ; i ++ ) { if ( a [ i ] == -1 ) { return i + ' ' ; } } return 0 ; }
You are given two strings s and t.
String t is generated by random shuffling string s and then add one more letter at a random position.
You are given two strings s and t . String t is generated by random shuffling string s and then add one more letter at a random position .
//array to store frequence of each letter //for loop to see which letter is used //with this for loop we didn't check the last letter of t (t has one more letter)