Find the difference between ASCII strings


  • 1

    Find the difference between ASCII strings

    public class Solution {
        public char findTheDifference(String s, String t) {
            int s_sum = getNumericalSum(s);
            int t_sum = getNumericalSum(t);
            return (char)(t_sum - s_sum);        
        }
        
        private int getNumericalSum(String input){
            int sum = 0;
            for(int i=0;i<input.length();i++){
                sum += (int)input.charAt(i);
            }
            return sum;
        }
    }
    

Log in to reply
 

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