Share my answer and find best answer.


  • 0
    J
    public class Solution {
    public boolean isAnagram(String s, String t) {
             if(s.length()!=t.length()){
        	return false;
        }
        if(s.length()==0){
        	return true;
        }
    	char[] c = s.toCharArray();
        char[] c1 = t.toCharArray();
    	//List<Integer> list = new ArrayList<>();
    	for(int i=0;i<c.length;i++){
    		for(int j = 0;j<c1.length;j++){
    			if(c1[j]==c[i]){
    				c1[j]='*';
    				break;
    			}
    		}
    	}
    	boolean result = true;
    	for(int i =0;i<c1.length;i++){
    		if(c1[i]!='*'){
    			result = false;
    			break;
    		}
    	}
    	return result;
    }
    

    }


Log in to reply
 

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