https://leetcode.com/problems/palindrome-permutation/
Given a string, determine if a permutation of the string could form a palindrome.
For example,
"code" -> False, "aab" ->
True, "carerac" -> True.
public class Solution {
public boolean canPermutePalindrome(String s) {
char[] c = s.toCharArray();
int[] i = new int[128];
for(char cc: c){
i[(int) cc]+=1;
}
boolean flag = true;
for(int ii: i){
if(ii%2!=0){
if(flag) flag=false;
else return false;
}
}
return true;
}
}Only at most one character's occurrence can be odd. Suppose charset is ASCII
本文介绍了一种算法,用于判断给定的字符串是否可以通过重新排列形成回文串。核心思路是检查字符串中每个字符出现次数的奇偶性,确保至多只有一个字符的出现次数为奇数。

被折叠的 条评论
为什么被折叠?



