1315. Sum of Nodes with Even-Valued Grandparent Given the root of a binary tree, return the sum of values of nodes with an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0. A grandparent of a node is the parent of its parent if it exists. 12345678910111213141516171819202122232425/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */class Solution { int helper(TreeNode* node, bool grand, bool parent) { if(!node) return 0; int res = grand ? node->val : 0; res += helper(node->left, parent, !(node->val & 1)); res += helper(node->right, parent, !(node->val & 1)); return res; }public: int sumEvenGrandparent(TreeNode* root) { return helper(root, false, false); }};