问题
给定一个字符串,判断该字符串中是否可以通过重新排列组合,形成一个回文字符串。
例子
思路
-
方法1
奇数个的字符为1个或者0个
-
方法2
代码
//方法1
class Solution {
public boolean canPermutePalindrome(String s) {
int[] arr = new int[128];
for(int i=0;i<s.length(); i++) {
char c = s.charAt(i);
if(arr[c]==1) arr[c]=0;
else arr[c]=1;
}
int res=0;
for(int n: arr){
res +=n;
}
return res==0||res==1?true:false;
}
}
//方法2