#242.Valid Anagram [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/valid-anagram/

class Solution {
    public boolean isAnagram(String s, String t) {
        //treated as constant space to store frequency of characters
        int[] freq = new int[26];

        for(char c : s.toCharArray()){
            freq[c - 'a'] ++;
        }

        for(char c : t.toCharArray()){
            freq[c - 'a'] --;
        }

        for(int i : freq){
            if(i != 0) return false;
        }

        return true;
    }
}