My java solution


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

    }


Log in to reply
 

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