-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutationPalindrome.java
More file actions
35 lines (30 loc) · 1002 Bytes
/
PermutationPalindrome.java
File metadata and controls
35 lines (30 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public static Boolean isPermutationPalindrome(String str) {
int bitVector = 0;
for (char c: str.toCharArray()){
if (c >= 'a' && c <= 'z'){
int char_value = c - 'a';
bitVector = toggle (bitVector, char_value);
System.out.println( c + " " + Integer.toString(bitVector, 2));
}
}
//System.out.println(onlyOneOdd(bitVector));
return (bitVector == 0 || onlyOneOdd(bitVector));
}
public static int toggle (int bitVector, int char_value){
if (char_value < 0){
return 0;
}
int current = 1 << char_value;
return (bitVector ^ current);
}
public static boolean onlyOneOdd(int bitVector){
if ((bitVector & (bitVector - 1)) == 0){
return true;
}
return false;
}
public static void main(String[] args){
System.out.println(isPermutationPalindrome("tact coa"));
}
}