Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

palindrome rearrange

# Python3 implementation to check if
# characters of a given string can
# be rearranged to form a palindrome
  
NO_OF_CHARS = 256
  
# function to check whether characters
# of a string can form a palindrome
  
  
def canFormPalindrome(st):
  
    # Create a count array and initialize
    # all values as 0
    count = [0] * (NO_OF_CHARS)
  
    # For each character in input strings,
    # increment count in the corresponding
    # count array
    for i in range(0, len(st)):
        count[ord(st[i])] = count[ord(st[i])] + 1
  
    # Count odd occurring characters
    odd = 0
  
    for i in range(0, NO_OF_CHARS):
        if (count[i] & 1):
            odd = odd + 1
  
        if (odd > 1):
            return False
  
    # Return true if odd count is 0 or 1,
    return True
  
  
# Driver code
if(canFormPalindrome("geeksforgeeks")):
    print("Yes")
else:
    print("No")
  
if(canFormPalindrome("geeksogeeks")):
    print("Yes")
else:
    print("No")
  
# This code is contributed by Nikita Tiwari.
Comment

PREVIOUS NEXT
Code Example
Python :: pyqt log widget thread safe 
Python :: NumPy fliplr Example 
Python :: NumPy bitwise_and Example When inputs are arrays 
Python :: setstylesheet python 
Python :: del mutiple indexes at once 
Python :: make all subplots same height 
Python :: NumPy bitwise_or Syntax 
Python :: NumPy packbits Code Packed array along axis 1 
Python :: django view - APIView (urls.py config) 
Python :: python code to scan paper table to excel 
Python :: # remove sensitive information like name, email, phone no from text 
Python :: dictionary display 
Python :: tkintre sub windows 
Python :: python replace date time column 
Python :: Visual Studio Code pylint: Error when all is ok 
Python :: city of stars how many words in a song python code 
Python :: python simplenamespace to json 
Python :: python code sample submission of codeforces 
Python :: sqlite basic 
Python :: Trying to set up flask with nginx and gunicorn 
Python :: python class reflect method of member instance 
Python :: check if id is present in elasticsearch using python 
Python :: converter json em form-data-encoded python 
Python :: found django install path 
Python :: how to split from a specific charecter tfrm the end of string 
Python :: Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/python/3.7.3 
Python :: Convert matlab to Python Reddit 
Python :: pygame mixer channel loop 
Python :: how to make download link in Jupyter appmode 
Python :: downolad fileby python requests 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =