Use subtraction


  • 0
    C
    class Solution {
        public char findTheDifference(String s, String t) {
            int sub = 0 ;
            for (int i = 0; i < s.length(); i++) {
                sub += t.charAt(i) -  s.charAt(i) ;
            }
            int c = t.charAt(t.length() - 1) - '0';
            sub += c;
            return (char) (sub + '0');
        }
    }
    

Log in to reply
 

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