Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- CHECK
- 병목
- IaC
- sns
- fcm
- 분산시스템
- rds
- Lamda
- lambda
- amazonqcli
- terraform
- SageMaker
- Validation
- kubernetes
- CAP
- serverless
- PACELC
- aws
- cloudwatch
Archives
- Today
- Total
잡다한 IT 지식
226. Invert Binary 본문
Majority Element - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com

[문제 설명]
노드를 좌우 대칭해서 반환하시오
[처음 생각한 접근 방법]
무지성 노드 교환
class Solution {
public TreeNode invertTree(TreeNode root) {
Queue<TreeNode> q = new LinkedList<>();
if (root == null) {
return null;
}
q.offer(root);
while (!q.isEmpty()) {
TreeNode head = q.poll();
TreeNode temp = head.left;
head.left = head.right;
head.right = temp;
if (head.left != null) {
q.offer(head.left);
}
if (head.right != null) {
q.offer(head.right);
}
}
return root;
}
}
'알고리즘 문제 풀이 > BFS' 카테고리의 다른 글
| 103. Binary Tree Zigzag Level Order Traversal (0) | 2021.07.22 |
|---|---|
| 559. Maximum Depth of N-ary Tree (0) | 2021.07.08 |
| 690. Employee Importance (0) | 2021.07.01 |
| BFS (0) | 2021.05.07 |
| 01 Matrix (0) | 2021.04.14 |