Leetcode Everyday: 266. Palindrome Permutation

来源:互联网 发布:制作游戏用什么软件 编辑:程序博客网 时间:2024/04/29 15:36

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



0 0
原创粉丝点击