Solution to Leetcode problem 971 Flip Binary Tree To Match Preorder Traversal
This is the third problem of the Leetcode contest 118. It is a problem on binary trees (My favorite kind of problem!). It is using the following 2 definitions:
- "A node in the binary tree can be flipped by swapping the left child and the right child of that node"
- Preorder traversal of a node: we report the current node's value, then preorder-traverse the left child, then preorder-traverse the right child
The question is: Given a binary tree T
, with nodes with unique values, and a array A
, is there a way to flip nodes of T
such that a preorder traversal of T
matches A
's values in order?
Read full article from Solution to Leetcode problem 971 Flip Binary Tree To Match Preorder Traversal
No comments:
Post a Comment