Simple Java Solution

  • 1
    public class Solution {
        public boolean isAnagram(String s, String t) {
            if(s.length()!=t.length()) return false;
            char a[]=s.toCharArray();
            char b[]=t.toCharArray();
            return Arrays.equals(a,b);

  • 3

    One suggestion: Always begin your code by adding null checks. null case is one of the, lets say, top five cases that the interviewer would want to check. Though the OJ didnt test for null inputs, its always a good habit . Hope this helps.

Log in to reply

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