Java Solution


  • 3
    B

    public class Solution {
    public char findTheDifference(String s, String t) {
    int sum1=0;

    	// In the loop below, add the previous value of sum,
    	// add the ASCII value of each character of string t
    	// and subtract ASCII value of each character of string s.
    	for(int i=0;i<s.length();i++){
            sum1=(int) (sum1+t.charAt(i)-s.charAt(i));
        }
        // Add the ASCII value of last character of the string t     
        sum1=(int) sum1+t.charAt(t.length()-1);
        
        return (char) sum1;
    }
    

    }


Log in to reply
 

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