Linear time, Constant space Java Solution


  • 0
    C
     public boolean isAnagram(String s, String t) {
    		if(s==null)
    			return (t==null);
    		if(t==null ||s.length()!=t.length())
    			return false;
    		
    		int[] arr = new int[256];
    		for(int i=0; i<s.length(); i++){
    			arr[s.charAt(i)]++;
    		}
    		for(int i=0; i<t.length(); i++){
    			if(arr[t.charAt(i)]--==0)
    				return false;
    		}
    		return true;
    	}

Log in to reply
 

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