250x250
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
- Union-find
- spring boot
- html
- 스택
- scanner
- 스프링부트
- priority_queue
- map
- union_find
- string
- CSS
- dfs
- List
- set
- sql
- deque
- date
- 힙덤프
- JPA
- 리소스모니터링
- Java
- NIO
- math
- javascript
- Properties
- GC로그수집
- alter
- BFS
- Calendar
- 큐
Archives
- Today
- Total
매일 조금씩
Leet code (Easy): 226. Invert Binary Tree - Java 본문
728x90
반응형
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public TreeNode invertTree(TreeNode root) {
invert(root);
return root;
}
private void invert(TreeNode node){
if(node != null){
TreeNode temp = node.left;
node.left = node.right;
node.right = temp;
invert(node.left);
invert(node.right);
}
}
}
728x90
반응형
'알고리즘 > Tree' 카테고리의 다른 글
Leet code (Easy): 572. Subtree of Another Tree - Java (0) | 2024.10.30 |
---|---|
Leet code (Hard): 297. Serialize and Deserialize Binary Tree - Java (0) | 2024.10.30 |
Leet code (Medium): 102. Binary Tree Level Order Traversal - Java (0) | 2024.10.29 |
Leet code (Hard): 124. Binary Tree Maximum Path Sum - Java (1) | 2024.10.29 |
Leet code (Easy): 100. Same Tree - Java (0) | 2024.10.28 |