feat: 2025-10-29打卡
This commit is contained in:
35
100.same-tree.java
Normal file
35
100.same-tree.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* @lc app=leetcode id=100 lang=java
|
||||
*
|
||||
* [100] Same Tree
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
/**
|
||||
* 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 boolean isSameTree(TreeNode p, TreeNode q) {
|
||||
if(p == null || q == null) {
|
||||
return p == q;
|
||||
}
|
||||
if(p.val != q.val) {
|
||||
return false;
|
||||
}
|
||||
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
39
101.symmetric-tree.java
Normal file
39
101.symmetric-tree.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* @lc app=leetcode id=101 lang=java
|
||||
*
|
||||
* [101] Symmetric Tree
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
/**
|
||||
* 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 boolean isSymmetric(TreeNode root) {
|
||||
return root == null ? true: isMirror(root.left, root.right);
|
||||
}
|
||||
|
||||
private boolean isMirror(TreeNode l, TreeNode r) {
|
||||
if(l == null || r == null) {
|
||||
return l == r;
|
||||
}
|
||||
if(l.val != r.val) {
|
||||
return false;
|
||||
}
|
||||
return isMirror(l.left, r.right) &&isMirror(l.right, r.left);
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user