Problem


Given a string, find out if its characters can be rearranged to form a palindrome.


Example


For inputString = "aabb", the output should be
palindromeRearranging(inputString) = true.

We can rearrange "aabb" to make "abba", which is a palindrome.


Input/Output

  • [input] string inputString

    A string consisting of lowercase English letters.

    Guaranteed constraints:
    1 ≤ inputString.length ≤ 50.

  • [output] boolean

    true if the characters of the inputString can be rearranged to form a palindrome, false otherwise.



Solution

def palindromeRearranging(inputString):

stringCount = [inputString.count(i) % 2 for i in set(inputString)]


return sum(stringCount) <= 1


*stringCount : input된 문자열에서 중복값을 없애고, 해당 문자를 for문으로 반환한 값을 2로 나눈 나머지 값을 리스트로 저장

'Programming > Algorithm' 카테고리의 다른 글

[Algorithm] arrayMaximalAdjacentDifference  (0) 2018.03.02
[Algorithm] areEquallyStrong  (0) 2018.03.02
[Algorithm] arrayChange  (0) 2018.02.26
[Algorithm] areSimilar  (0) 2018.02.26
[Algorithm] addBoarder  (0) 2018.02.26

+ Recent posts