Share My Java Solution by Sorting


  • 1
    R
    public class Solution {
        public  boolean isAnagram(String s, String t) {
            if(s == null || t == null)
            	return false;
            return(sortString(s).equals(sortString(t)));
        }
        public  String sortString(String s){
        	char[] temp = s.toCharArray();
        	Arrays.sort(temp);
        	String result = new String(temp);
        	return result;
        }
    }

Log in to reply
 

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