C++ Right-To-Left inorder traversal


  • 0
    // OJ: https://leetcode.com/problems/convert-bst-to-greater-tree
    // Auther: github.com/lzl124631x
    // Time: O(N)
    // Space: O(logN)
    class Solution {
    private:
      int sum = 0;
    public:
      TreeNode* convertBST(TreeNode* root) {
        if (!root) return NULL;
        convertBST(root->right);
        sum = (root->val += sum);
        convertBST(root->left);
        return root;
      }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.