Palindrome Permutation II

Problem: Palindrome Permutation II

We can first establish a dictionary for characters to judge whether the word can form a permutation and find the single character if there's such one. Then we can use backtracking to construct a palindrome. There's another solution here using swapping to construct permutation.

Code in Python:

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def levelOrderBottom(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        if not root: return []
        res = []
        level = [root]
        while level:
            res = [level] + res
            next = []
            for node in level:
                if node.left: next.append(node.left)
                if node.right: next.append(node.right)
            level = next
        return res

results matching ""

    No results matching ""