Game of Thrones - I

  • + 2 comments

    Merge odd and even situations. That means regardless the len(str) is odd or even, just when the count of each elements have no more than ONE, the str is palindrome.

    from collections import Counter
    def gameOfThrones(s):
        # Complete this function
        num_odd = 0
        s1 = Counter(s)
        for each in s1.values():
            if each % 2 != 0:
                num_odd += 1
                # when num_odd > 1, not palindrome
                if num_odd > 1:
                    return 'NO'
        return ('YES')