LeetCode solutions by tgic

Palindrome Permutation

https://leetcode.com/problems/palindrome-permutation

Last Update 2015-08-24 09:21:42 +0000 View on Github

Counting Map

http://stackoverflow.com/questions/81346/most-efficient-way-to-increment-a-map-value-in-java

Source code Read on Github

 1 public class Solution {
 2     public boolean canPermutePalindrome(String s) {
 3         Map<Character, Integer> m = new HashMap<>();
 4 
 5         for(char c : s.toCharArray()){
 6             Integer i = m.get(c);
 7 
 8             if(i == null){
 9                 m.put(c, 1);
10             } else {
11                 m.put(c, i + 1);
12             }
13         }
14 
15         int single = 0;
16 
17         for(int v : m.values()){
18             if(v % 2 == 1){
19                 single++;
20             }
21 
22             if(single > 1){
23                 return false;
24             }
25         }
26 
27         return true;
28     }
29 }
comments powered by Disqus

LeetCode solutions by tgic

  • LeetCode solutions by tgic
  • [email protected]
  • Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
  • tg123
  • tg123/leetcode

LeetCode java solutions by tgic