Why is my solution showing incorrect??


  • 0
    R

    Below is my code for the question and it says I return false for input "", "". I tried the same code on eclipse with the same input and my code returns true. But here it says my code returns false.

    public class Solution {
        public boolean isAnagram(String s, String t) {
            if (s.length() != t.length()){
                return false;
            }
            String[] sArray = s.split("");
            String[] tArray = t.split("");
            Arrays.sort(sArray);
            Arrays.sort(tArray);
            for (int i = 0; i < sArray.length; i++){
                if (sArray[i] != tArray[i]){
                    return false;
                }
            }
            return true;
        }
    }

Log in to reply
 

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