File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 54
54
|276|[ Paint Fence] ( https://leetcode.com/problems/paint-fence/ ) |[ Solution] ( ../../blob/master/EASY/src/easy/PaintFence.java ) | O(n)|O(1) | Easy| DP
55
55
| 273| [ Integer to English Words] ( https://leetcode.com/problems/integer-to-english-words/ ) | [ Solution] |
56
56
|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
57
58
| 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|
58
59
| 259| [ 3Sum Smaller] ( https://leetcode.com/problems/3sum-smaller/ ) | [ Solution] ( ../../blob/master/MEDIUM/src/medium/_3Sum_Smaller.java ) | O(n^2)| O(1) | Medium|
59
60
|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
You can’t perform that action at this time.
0 commit comments