找LeetCode上简单的题目来撑过30天啦(DAY8)

题号;100 标题:Same Tree 难度;Easy

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

Example 1:

Input: p = [1,2,3], q = [1,2,3]
Output: true

Example 2:

Input: p = [1,2], q = [1,null,2]
Output: false

Example 3:

Input: p = [1,2,1], q = [1,1,2]
Output: false

Constraints:

The number of nodes in both trees is in the range [0, 100].
-104 <= Node.val <= 104


我的程序码

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

bool checkR();

bool checkL(struct TreeNode* a, struct TreeNode* b){
    if((a == NULL &&  b != NULL)||(a != NULL &&  b == NULL) ){
        return false;
    }else if(a == NULL &&  b == NULL) {
        return true;
    }else if(a->val != b->val){
        return false;
    }else{
       return (checkR(a->right,b->right) && checkL(a->left,b->left)); 
    }
    return true;
}

bool checkR(struct TreeNode* c, struct TreeNode* d){
    if((c == NULL &&  d != NULL)||(c != NULL &&  d == NULL) ){
        return false;
    }else if(c == NULL &&  d == NULL){
        return true;
    }else if(c->val != d->val){
        return false;
    }else{
       return (checkR(c->right,d->right) && checkL(c->left,d->left)); 
    }
    return true;
}

bool isSameTree(struct TreeNode* p, struct TreeNode* q){
    if((p == NULL &&  q != NULL)||(p != NULL &&  q == NULL) ){
        return false;
    }else if(p == NULL &&  q == NULL){
        return true;
    }else if(p->val != q->val){
        return false;
    }else{
        return (checkL(p->left,q->left) && checkR(p->right,q->right));
    }
    return true;
}

逻辑
检查每个节点的左边跟右边是否相等,不相等就return false

花比较多的时间在
资料结构的理解跟递回

题号:620 标题:Not Boring Movies 难度:Easy

Table: Cinema

id is the primary key for this table.
Each row contains information about the name of a movie, its genre, and its rating.
rating is a 2 decimal places float in the range [0, 10]

Write an SQL query to report the movies with an odd-numbered ID and a description that is not "boring".

Return the result table in descending order by rating.

The query result format is in the following example:

Cinema table:

Result table:

We have three movies with odd-numbered ID: 1, 3, and 5. The movie with ID = 3 is boring so we don't include it in the answer.


SQL指令

select * from Cinema where ((id%2) <> 0 ) and description <> "boring"  order by rating  desc;

DAY8心得
上班好累/images/emoticon/emoticon09.gif


<<:  Day8 Redis组态档设定-KEYS TRACKING/SECURITY/CLIENT

>>:  Day_11 : 让 Vite 来开启你的 Vue 之 Config 常见配置 (Vite 最终篇 XD)

D22. 学习基础C、C++语言

D22. 题目练习UVA11565 #include <stdio.h> #includ...

9/29(三) 制造业资安趋势:永续营业风险大解密线上研讨会

制造业是台湾经济的生力军,疫情延烧并未影响营运,资安事件反而成为不定时炸弹,造成企业商誉甚或营收受损...

[Lesson25] Kotlin - Array

基本型态阵列 Kotlin 已经有内建一些阵列物件,如 ByteArray、IntArray、Dou...

【从零开始的Swift开发心路历程-Day7】简易调色盘Part3(完)

昨天我们做到ImageView及TextField会根据Slider的左右滑动而改变颜色及数值,但是...

Station list screen (2)

上一篇我们完成了 StationListAdapter,我们现在会继续车站列表的 UI 部分。 St...