C++ Solution using ASCII values


  • 1

    class Solution {
    public:
    char findTheDifference(string s, string t) {
    int sum1=0, sum2=0;
    for(int i=0;i<s.length();i++)
    {
    sum1 = sum1 + s[i];
    }
    for(int i=0;i<t.length();i++)
    {
    sum2 = sum2 + t[i];
    }
    char c = sum2-sum1;
    return c;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.