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
- implement
- Number Theory
- string
- greedy
- Data Structure
- Counting
- 자바
- array
- dynamic programming
- java
- simulation
- 코테
- 코딩테스트
- Method
- Class
- hash table
- Matrix
- two pointers
- geometry
- bit manipulation
- SQL
- Tree
- 구현
- Binary Search
- Stack
- database
- 파이썬
- sorting
- Binary Tree
- Math
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 100. Same Tree 본문
1. Input
1) 이진 트리 p
2) 이진 트리 q
- 이진 트리는 문제에 제공되는 TreeNode 클래스로 구현한다.
2. Output
1) p와 q가 같은 트리이면 true, 다르면 false를 반환
3. Constraint
1) 한 트리의 노드 수의 범위는 [0, 100]이다.
2) - 10^4 <= Node.val <= 10^4
4. Example


5. Code
1) 첫 코드(2023/01/11)
/**
* 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;
* }
* }
*/
boolean answer;
if(p==null && q==null)
answer = true;
else if(p!=null && q!=null && p.val==q.val)
answer = isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
else
answer = false;
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2042. Check if Numbers Are Ascending in a Sentence (0) | 2023.01.12 |
---|---|
[프로그래머스/Lv.1] 푸드 파이트 대회 (0) | 2023.01.11 |
[LeetCode/Easy] 2037. Minimum Number of Moves to Seat Everyone (0) | 2023.01.11 |
[LeetCode/Easy] 2022. Convert 1D Array Into 2D Array (0) | 2023.01.11 |
[LeetCode/Easy] 2016. Maximum Difference Between Increasing Elements (0) | 2023.01.11 |