7ms Java Solution.


  • 1
    H

    Need suggestions to improve this.

    public class Solution {
        public char findTheDifference(String s, String t) {
            char[] tot=(s+t).toCharArray();
            if(tot.length==0) return 0;
            int i=0;
            for(i=tot.length-1;i>0;i--){
                tot[i-1]=(char)((int)tot[i]^(int)tot[i-1]);
            }
            return tot[i];
        }
    }
    

Log in to reply
 

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