aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-15 14:16:48 +0800
committercrupest <crupest@outlook.com>2020-08-15 14:16:48 +0800
commitc47e2d04ce0bbc73ca29ea45f1e8e246fbd340d6 (patch)
tree64dc3693b83f4e3112ac29cd8d2f2753a41a9fc0
parentb888edbc547ecdd8d763657248e81bbea38f2983 (diff)
downloadcrupest-c47e2d04ce0bbc73ca29ea45f1e8e246fbd340d6.tar.gz
crupest-c47e2d04ce0bbc73ca29ea45f1e8e246fbd340d6.tar.bz2
crupest-c47e2d04ce0bbc73ca29ea45f1e8e246fbd340d6.zip
import(solutions): Add problem 965 .
-rw-r--r--works/solutions/cpp/965.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/works/solutions/cpp/965.cpp b/works/solutions/cpp/965.cpp
new file mode 100644
index 0000000..fd2bff6
--- /dev/null
+++ b/works/solutions/cpp/965.cpp
@@ -0,0 +1,29 @@
+#include <cstddef>
+
+struct TreeNode
+{
+ int val;
+ TreeNode *left;
+ TreeNode *right;
+ TreeNode(int x) : val(x), left(NULL), right(NULL) {}
+};
+
+class Solution
+{
+public:
+ static bool traverse(TreeNode *root, int val)
+ {
+ if (root == NULL)
+ return true;
+ if (root->val != val)
+ return false;
+ return traverse(root->left, root->val) && traverse(root->right, root->val);
+ }
+
+ bool isUnivalTree(TreeNode *root)
+ {
+ if (root == NULL)
+ return true;
+ return traverse(root, root->val);
+ }
+}; \ No newline at end of file