Leetcode-965 Univalued Binary Tree(單值二叉樹)
阿新 • • 發佈:2018-12-30
ret public ued als tree int false 二叉樹 col
1 class Solution 2 { 3 public: 4 bool PreOrderTraverse (TreeNode* T,int data) 5 { 6 if(T) 7 { 8 if(T->val!=data) 9 return false; 10 if(!PreOrderTraverse (T -> left,data)) 11 returnfalse; 12 if(!PreOrderTraverse (T -> right,data)) 13 return false ; 14 } 15 return true; 16 } 17 bool isUnivalTree(TreeNode* root) 18 { 19 return PreOrderTraverse(root,root->val); 20 }21 };
Leetcode-965 Univalued Binary Tree(單值二叉樹)