LeetCode题目总结

  1. Binary Tree Inorder Traversal 二叉树的中序遍历
    解法一:递归
    // Recursion
    class Solution {
    public:
    vector inorderTraversal(TreeNode *root) {
    vector res;
    inorder(root, res);
    return res;
    }
    void inorder(TreeNode *root, vector &res) {
    if (!root) return;
    if (root->left) inorder(root->left, res);
    res.push_back(root->val);
    if (root->right) inorder(root->right, res);
    }
    };

猜你喜欢

转载自blog.csdn.net/qq_24477851/article/details/88085176
今日推荐