Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created January 1, 2019 09:14
Show Gist options
  • Save fpdjsns/7a0ca7edb3d312c4e587ea0bbd0499da to your computer and use it in GitHub Desktop.
Save fpdjsns/7a0ca7edb3d312c4e587ea0bbd0499da to your computer and use it in GitHub Desktop.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSameValue(TreeNode* root, int val){
if(root == NULL) return true;
if(root->val != val) return false;
bool ans = isSameValue(root->left, val);
ans &= isSameValue(root->right, val);
return ans;
}
bool isUnivalTree(TreeNode* root) {
return isSameValue(root, root->val);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment