9ms Java solution


  • 14
    V

    public class Solution {

    public boolean isAnagram(String s, String t) {
        
        if(s.length() != t.length()) {
            return false;
        }
        
        int[] count = new int[26];
    
        for(int i = 0; i < s.length(); i++) {
            count[s.charAt(i) - 'a']++;
            count[t.charAt(i) - 'a']--;
        }
        
        for(int x : count) {
            if(x != 0) return false;
        }
        
        return true;
    }
    

    }


  • 0
    J

    super clean! thanks. This is a very good solution


Log in to reply
 

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