Given a string, write a function to check if it is a permutation of a palin drome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. The palindrome does not need to be limited to just dictionary words.
Example1:
Input: "tactcoa" Output: true(permutations: "tacocat"、"atcocta", etc.)
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/palindrome-permutation-lcci 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class Solution {
public boolean canPermutePalindrome(String s) {
int[] map = new int[256];
int count = 0;
for (char c : s.toCharArray()) {
if ((map[c]++ & 1) == 1) {
count--;
} else {
count++;
}
}
return count <= 1;
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有