LeetCode965. 单值二叉树

题目

 1 class Solution {
 2 public:
 3     int flag = 0;
 4     bool isUnivalTree(TreeNode* root){
 5         isUnivalTree1(root,root->val);
 6         if(flag == 0) return true;
 7         else return false;
 8     }
 9     void isUnivalTree1(TreeNode* root,int tmp) {
10         if(root!=NULL){
11             isUnivalTree1(root->left,tmp);
12             if(root->val != tmp) flag = 1;
13             isUnivalTree1(root->right,tmp);
14             
15         }
16     }
17 };

 

posted @ 2021-01-13 16:32  Uitachi  阅读(56)  评论(0编辑  收藏  举报