AIRSATM / My-progress

0 stars 0 forks source link

Root-Equals-Sum-of-Children #2

Open AIRSATM opened 1 month ago

AIRSATM commented 1 month ago

class Solution { public: bool checkTree(TreeNode* root) { if (root->left->val + root->right->val != root->val) return false; else return true; } };

AIRSATM commented 1 month ago

Alternative var:(^-^) class Solution { public: bool checkTree(TreeNode* root) { int res = root->val; int left_res = root->left->val; int right_res = root->right->val; bool tes = (res == left_res + right_res)? true : false; return tes; } };