Check if characters of a given string can be rearranged to form a palindrome | C ++ Implementation of the above approach ; bitvector to store the record of which character appear odd and even number of times ; Driver Code
# include <bits/stdc++.h> NEW_LINE using namespace std ; bool canFormPalindrome ( string a ) { int bitvector = 0 , mask = 0 ; for ( int i = 0 ; a [ i ] != ' \0' ; i ++ ) { int x = a [ i ] - ' a ' ; mask = 1 << x ; bitvector = bitvector ^ mask ; } return ( bitvector & ( bitvector - 1 ) ) == 0 ; } int main ( ) { if ( canFormPalindrome ( " geeksforgeeks " ) ) cout << ( " Yes " ) << endl ; else cout << ( " No " ) << endl ; return 0 ; }