266 Palindrome Permutation

Input: s = "code"
Output: False
Explanation:
No solution
Input: s = "aab"
Output: True
Explanation:
"aab" --> "aba"
Input: s = "carerac"
Output: True
Explanation:
"carerac" --> "carerac"
class Solution:
def canPermutePalindrome(self, s):
cnt,total_odds=0,0
hash=dict()
for i in s:
if i in hash:
hash[i]+=1
else:
hash[i]=1
cnt+=1
print(cnt)
for i in hash:
total_odds+=hash[i]%2
return(total_odds<=1)
class Solution:
def canPermutePalindrome(self, s):
set_=set()
for i in s:
if i in set_:
set_.remove(i)
else:
set_.add(i)
return(len(set_)<=1)
class Solution:
def canPermutePalindrome(self, s):
mask=0
for c in s:
if (mask & 1<<ord(c) == 0):
mask|=1<<ord(c)
else:
mask&=~(1<<ord(c))
return(mask&(mask-1)==0)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.