Last active
August 28, 2018 07:38
-
-
Save lienista/b4a51577a7dbad67a8e33d379f5e8f23 to your computer and use it in GitHub Desktop.
Algorithms in Javascript: CTCI 1.4 Palindrome Permutation: Given a string, determine if it is a permutation of a palindrome.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const isPalindrome = (s1) => { | |
| let charMap = new Map(); | |
| for(let i=0; i <s1.length; i++){ | |
| if(charMap.get(s1[i])) { | |
| charMap.delete(s1[i]); | |
| } else { | |
| charMap.set(s1[i], 1); | |
| } | |
| } | |
| if(s1.length%2 === 0 && charMap.size === 0 || | |
| s1.length%2 === 1 && charMap.size === 1) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| let x = 'abbc'; | |
| console.log(isPalindrome(x)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment