my java solution


  • 0
    C
       import java.util.*;
       public class Solution {
       public char findTheDifference(String s, String t) {
    	Hashtable<Character,Integer> table = new Hashtable();
    	if(s.length() == 0)
    		return t.charAt(0);
    	else if(t.length()==0)
    	    return s.charAt(0);
    	for(int i=0;i<s.length();i++)
    	{
    		Integer count = table.get(s.charAt(i));
    		if(count == null)
    			table.put(s.charAt(i), 1);
    		else
    			table.put(s.charAt(i), ++count);
    	}
    	for(int i=0;i<t.length();i++)
    	{
    		Integer count = table.get(t.charAt(i));
    		if((count == null) || (count ==0))
    			return t.charAt(i);
    		else
    			table.put(t.charAt(i), --count);
    	}
    	return ' ';
    }
    

    }


Log in to reply
 

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