Skip to content

Instantly share code, notes, and snippets.

@sumedhaagarwal
Created May 17, 2021 16:27
Show Gist options
  • Save sumedhaagarwal/b74872ea0728d522f675363ebd8ad4c9 to your computer and use it in GitHub Desktop.
Save sumedhaagarwal/b74872ea0728d522f675363ebd8ad4c9 to your computer and use it in GitHub Desktop.
PalindromePermutation
#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