daily pastebin goal
11%
SHARE
TWEET

409. Longest Palindrome

HXXXXJ Feb 18th, 2019 (edited) 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     func longestPalindrome(_ s: String) -> Int {
  2.         var map = [Character : Int]()
  3.        
  4.         for char in s {
  5.             map[char, default: 0] += 1
  6.         }
  7.         var odd = false
  8.         let res = map.values.reduce(0){
  9.             if $1 % 2 == 1 { odd = true}
  10.             return $0 + $1/2
  11.         }
  12.         return res*2 + (odd ? 1 : 0)
  13.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top