Skip to content

Latest commit

 

History

History

flip-equivalent-binary-trees

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Flip equivalent binary trees

Problem link

Solutions

Solution.py

# https://leetcode.com/problems/flip-equivalent-binary-trees/

class Solution:
    def flipEquiv(
        self, root1: Optional[TreeNode], root2: Optional[TreeNode]
    ) -> bool:
        def vec(root):
            if not root: 
                return [-1]
            lc, rc = vec(root.left), vec(root.right)
            return [root.val] + sorted([lc, rc])
        return vec(root1) == vec(root2)

Tags