Accepted Java O(n) Solution 3ms


  • 0
    S

    public class Solution {
    public boolean isAnagram(String s, String t) {

    if(s.length()!=t.length()){return false;}
    

    int[] c = new int[26];

    for(char c1: s.toCharArray()){
    c[c1-'a']++;
    }
    for(char c1:t.toCharArray()){
    c[c1-'a']--;
    if(c[c1-'a']<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.