leetCode538

中序遍历

/**
 * 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 {
private:
    int num = 0;
public:
    TreeNode* convertBST(TreeNode* root) {
        if(!root) return root;
        convertBST(root->right);
        root->val+=num;
        num = root->val;
        convertBST(root->left);
        return root;
    }
};

 


版权声明:本文为qq_36257146原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。