Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 866c184

Browse files
Update and rename 156.Binary Tree Upside Down.cpp to 156.Binary-Tree-Upside-Down.cpp
1 parent dff4abf commit 866c184

File tree

2 files changed

+30
-44
lines changed

2 files changed

+30
-44
lines changed

‎Tree/156.Binary-Tree-Upside-Down/156.Binary Tree Upside Down.cpp‎

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
TreeNode* upsideDownBinaryTree(TreeNode* root)
13+
{
14+
if (root==NULL) return NULL;
15+
if (root->left==NULL && root->right==NULL) return root;
16+
17+
TreeNode* head = upsideDownBinaryTree(root->left);
18+
TreeNode* node = head;
19+
20+
while (node->right!=NULL)
21+
node=node->right;
22+
23+
node->left = root->right;
24+
node->right = root;
25+
root->left=NULL;
26+
root->right=NULL;
27+
28+
return head;
29+
}
30+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /