算法題-字符串置換

public class Solution {
    /**
     * @param A: a string
     * @param B: a string
     * @return: a boolean
     */
    public boolean Permutation(String A, String B) {
    	boolean lenJudge = (A.length() ^ B.length()) == 0;
    	if(!lenJudge)return false; 
    	
    	char [] aArr = sort(A.toCharArray());
    	char [] bArr = sort(B.toCharArray());
    	
    	return eq(aArr, bArr);
    }
    
    private static char[] sort(char[] cs) {
    	for(int i = 0; i < cs.length - 1; i++) {
    		for (int j = i + 1; j < cs.length; j++) {
	       		if(cs[i] - cs[j] > 0) {
	       			char tmp = cs[i];
	       			cs[i] = cs[j];
	       			cs[j] = tmp;
	       		}
			}
    	}
    	return cs;
    }
    
    private static boolean eq(char []  aArr, char [] bArr) {
    	for (int i = 0; i < bArr.length; i++) {
			if(aArr[i] ^ bArr[i] != 0) {
				return false;
			}
		}
    	return true;
    }
}
相關文章
相關標籤/搜索