Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 404865d

Browse files
palindrome permutation
1 parent cbba375 commit 404865d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package easy;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class PalindromePermutation {
7+
8+
public boolean canPermutePalindrome(String s) {
9+
10+
char[] chars = s.toCharArray();
11+
Map<Character, Integer> map = new HashMap<Character, Integer>();
12+
for(char c : chars){
13+
if(!map.containsKey(c)) map.put(c, 1);
14+
else map.put(c, map.get(c)+1);
15+
}
16+
int evenCount = 0;
17+
for(Map.Entry<Character, Integer> e : map.entrySet()){
18+
if(e.getValue() % 2 != 0) evenCount++;
19+
if(evenCount > 1) return false;
20+
}
21+
return true;
22+
23+
}
24+
25+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
|276|[Paint Fence](https://leetcode.com/problems/paint-fence/)|[Solution](../../blob/master/EASY/src/easy/PaintFence.java)| O(n)|O(1) | Easy| DP
5555
|273|[Integer to English Words](https://leetcode.com/problems/integer-to-english-words/)|[Solution]|
5656
|270|[Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value/)|[Solution](../../blob/master/EASY/src/easy/ClosestBinarySearchTreeValue.java)| O(h)|O(1) | Easy| DFS
57+
|266|[Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation/)|[Solution](../../blob/master/EASY/src/easy/PalindromePermutation.java)| O(n)|O(1) | Easy| HashMap
5758
|261|[Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree/)|[Solution](../../blob/master/MEDIUM/src/medium/GraphValidTree.java)| O(V+E)|O(V+E) | Medium|
5859
|259|[3Sum Smaller](https://leetcode.com/problems/3sum-smaller/)|[Solution](../../blob/master/MEDIUM/src/medium/_3Sum_Smaller.java)| O(n^2)|O(1) | Medium|
5960
|257|[Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)|[Solution](../../blob/master/EASY/src/easy/BinaryTreePaths.java) | O(n*h) | O(h) | DFS/Recursion

0 commit comments

Comments
 (0)