[Leetcode] 226. Invert Binary Tree
Algorithm2021. 9. 9. 19:10
반응형
Identifying the Problem
모든 이진트리를 뒤집는다.
Organizing thoughts
Sourcecode
class Solution {
public:
TreeNode* invertTree(TreeNode* root)
{
if(!root) return NULL; //탈출 조건
swap(root->left, root->right); //왼쪽과 오른쪽 node를 뒤집음
invertTree(root->left); //재귀 탐색
invertTree(root->right);
return root;
}
};
반응형
'Algorithm' 카테고리의 다른 글
[Leetcode] 102. Binary Tree Level Order Traversal (0) | 2021.09.11 |
---|---|
[Leetcode] 124. Binary Tree Maximum Path Sum (0) | 2021.09.11 |
[Leetcode] 104. Maximum Depth of Binary Tree (0) | 2021.09.09 |
[Leetcode] 647. Palindromic Substrings (0) | 2021.09.09 |
[Leetcode] 5. Longest Palindromic Substring (0) | 2021.09.06 |
댓글()