First, when adding the char to the array, why does it add +1 ?
Why is the algorithm looking to see if the char is even or odd?
package com.codegym.task.task39.task3908;
/*
Is a palindrome possible?
*/
public class Solution {
public static void main(String[] args) {
}
public static boolean isPalindromePermutation(String s) {
boolean foundOdd = false;
int[] tableCount = new int[256];
for(char c : s.toLowerCase().toCharArray()) {
tableCount[c] += 1;
}
for(int count : tableCount) {
if (count % 2 != 0) {
if (foundOdd) {
return false;
}
foundOdd = true;
}
}
return true;
}
}
Requirements
Is a palindrome possible?
Implement the isPalindromePermutation(String s) method. It should return true if you can make a palindrome from all the characters in string s. Otherwise, it should return false.
The passed string includes only ASCII characters.
Ignore the case of the letters.
Requirements:
1. The isPalindromePermutation method should return true if you can make a palindrome by rearranging the characters in the passed string.
2. The isPalindromePermutation method should return false if you cannot make a palindrome by rearranging the characters in the passed string.
3. The isPalindromePermutation method must be public.
4. The isPalindromePermutation method must be static.