Tree Invert
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given a binary tree. Invert it. For each node:
left child must become right child;
right child must become left child;
Definition of a tree:
// Java class TreeNode { public: int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; left = NULL; right = NULL; };
// C++ class TreeNode { public: int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} };
Implement function Invert that returns the pointer to the inverted tree.
// Java TreeNode Invert(TreeNode tree)
// C++ TreeNode* Invert(TreeNode *tree)
Example
Function Invert returns res - pointer to the inverted tree.
Submissions 1K
Acceptance rate 61%