leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0965.cpp (462B)
0 class Solution {
1 public:
2 bool isUnivalTree(TreeNode *root) {
3 if (!root) return true;
4 int val = root->val;
5 stack<TreeNode *> st;
7 st.push(root);
8 while (!st.empty()) {
9 TreeNode *root = st.top();
10 st.pop();
11 if (root->val != val) return false;
12 if (root->left) st.push(root->left);
13 if (root->right) st.push(root->right);
14 }
16 return true;
17 }
18 };