You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (root == NULL) returntrue; // se a raiz for nula, retorna true
18
+
if (root->left == NULL && root->right == NULL) { // se a raiz nΓ£o for nula, mas os filhos forem nulos, retorna true
19
+
count++; // incrementa o contador
20
+
returntrue; // retorna true se a raiz nΓ£o for nula e os filhos forem nulos
21
+
}
22
+
bool left = isUnivalTree(root->left); // chama a funΓ§Γ£o isUnivalTree para o filho da esquerda
23
+
bool right = isUnivalTree(root->right); // chama a funΓ§Γ£o isUnivalTree para o filho da direita
24
+
if (left && right) { // se os filhos forem unival
25
+
if (root->left != NULL && root->val != root->left->val) returnfalse; // se o filho da esquerda nΓ£o for nulo e o valor da raiz for diferente do valor do filho da esquerda, retorna false
26
+
if (root->right != NULL && root->val != root->right->val) returnfalse; // se o filho da direita nΓ£o for nulo e o valor da raiz for diferente do valor do filho da direita, retorna false
27
+
count++; // incrementa o contador
28
+
returntrue; // retorna true se os filhos forem unival
29
+
}
30
+
returnfalse; // retorna false se os filhos nΓ£o forem unival
31
+
}
32
+
private:
33
+
boolisUnivalTree(TreeNode* root, int val) {
34
+
if (root == NULL) returntrue;
35
+
if (root->val == val) { // se o valor da raiz for igual ao valor passado
36
+
returnisUnivalTree(root->left, val) && isUnivalTree(root->right, val); // se o valor da raiz for igual ao valor passado, chama a funΓ§Γ£o isUnivalTree para o filho da esquerda e para o filho da direita
#### Click [__*here*__](https://leetcode.com/problems/number-of-good-pairs/) to visit a similar question on [*LeetCode*](https://leetcode.com/).
107
107
@@ -115,7 +115,7 @@ An XOR linked list is a more memory efficient doubly linked list. Instead of eac
115
115
116
116
If using a language that has no pointers (such as Python), you can assume you have access to `get_pointer` and `dereference_pointer` functions that converts between nodes and memory addresses.
#### Click [__*here*__](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/) to visit a similar question on [*LeetCode*](https://leetcode.com/).
120
120
121
121
---
@@ -128,7 +128,31 @@ Given the mapping `a = 1, b = 2, ... z = 26`, and an encoded message, count the
128
128
For example, the message `'111'` would give 3, since it could be decoded as `'aaa'`, `'ka'`, and `'ak'`.
129
129
You can assume that the messages are decodable. For example, `'001'` is not allowed.
0 commit comments