Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0741b3b

Browse files
committed
add folder & cpp(0ms) version
1 parent 33e4af5 commit 0741b3b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
private:
12+
bool isUnivalVal(TreeNode* r, int val)
13+
{
14+
if (val != r->val)
15+
return false ;
16+
17+
if (r->left && !isUnivalVal(r->left, val))
18+
return false ;
19+
if (r->right && !isUnivalVal(r->right, val))
20+
return false ;
21+
22+
return true ;
23+
}
24+
public:
25+
bool isUnivalTree(TreeNode* root) {
26+
if (nullptr == root)
27+
return true ;
28+
return isUnivalVal(root, root->val) ;
29+
}
30+
} ;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /