forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_266.java
33 lines (28 loc) · 863 Bytes
/
_266.java
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
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _266 {
public static class Solution1 {
public boolean canPermutePalindrome(String s) {
char[] chars = s.toCharArray();
Map<Character, Integer> map = new HashMap<>();
for (char c : chars) {
if (!map.containsKey(c)) {
map.put(c, 1);
} else {
map.put(c, map.get(c) + 1);
}
}
int evenCount = 0;
for (Map.Entry<Character, Integer> e : map.entrySet()) {
if (e.getValue() % 2 != 0) {
evenCount++;
}
if (evenCount > 1) {
return false;
}
}
return true;
}
}
}