Java solution for unicode characters


  • 0
    L
        public boolean isAnagram(String s, String t) {
            if (s.length() != t.length()){
                return false;
            }
    
            char[] sC = s.toCharArray();
            char[] tC = t.toCharArray();
            int[] intArray = new int[128];
    
            for (char c : sC) {
                intArray[Character.getNumericValue(c)]++;
            }
    
            for (char c : tC) {
                intArray[Character.getNumericValue(c)]--;
            }
    
            for (int i : intArray) {
                if (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.