Created
May 17, 2021 16:27
-
-
Save sumedhaagarwal/b74872ea0728d522f675363ebd8ad4c9 to your computer and use it in GitHub Desktop.
PalindromePermutation
This file contains 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
#include <bits/stdc++.h> | |
using namespace std; | |
int bitVector,mask; | |
string str; | |
bool powerof2(int x){ | |
return (x&(x-1))==0; | |
} | |
void toggle(int x){ | |
mask=1<<x; | |
if((bitVector&mask) == 0) | |
bitVector|=mask; | |
else | |
bitVector&=~mask; | |
} | |
bool isPermutationOfPalindrome(){ | |
for(char c:str){ | |
int x=c-'a'; | |
toggle(x); | |
} | |
return bitVector==0 or powerof2(bitVector); | |
} | |
int main() { | |
cin>>str; | |
if(isPermutationOfPalindrome()) | |
cout<<"YES"<<endl; | |
else | |
cout<<"NO"<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment