Flip a Tree Left to Right

Implement flipTree

You are given the root of a binary tree. Flip it left to right: at every node the left and right children trade places, all the way down. Return the root of the flipped tree.

You can build a fresh mirrored copy, or you can reuse the existing nodes and just swap their child pointers as you visit them.

Example 1:

Input: root = [10,6,14,3,8,null,17]

Output: [10,14,6,17,null,8,3]

Example 2:

Input: root = [5,2]

Output: [5,null,2]

Example 3:

Input: root = []

Output: []

+ 11 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ number of nodes ≤ 100
  • ●−100 ≤ node.val ≤ 100
  • ●The tree is given as its root node (null for an empty tree); each node has a val, a left child and a right child
  • ●Return the root of the tree after swapping the left and right children of every node (the whole tree becomes its own mirror image). The result is compared as a level-order list

root =

[10, 6, 14, 3, 8, null, 17]