题意:把二叉查找树每个节点的值都加上比它大的节点的值。
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int sum = 0; TreeNode* convertBST(TreeNode* root) { if(root == NULL) return NULL; convertBST(root -> right); sum += root -> val; root -> val = sum; convertBST(root -> left); return root; } };