 DAY 8
0
AI & Data

找LeetCode上簡單的題目來撐過30天啦(DAY8)

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 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;
}

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心得