Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎵文思泉涌🎵 #8

Open
Alex660 opened this issue Mar 30, 2020 · 1 comment
Open

🎵文思泉涌🎵 #8

Alex660 opened this issue Mar 30, 2020 · 1 comment

Comments

@Alex660
Copy link
Owner

Alex660 commented Mar 30, 2020

各位大佬有什么更多、更好的解法可以提出,并收录进去,就成了大家的知识宝库、面试宝典,谢谢大家的支持哇♥️♥️♥️

@HumanSean
Copy link

HumanSean commented Apr 24, 2020

提一个三序遍历的递归解法:

var preorderTraversal = function(root, arr = []) {
    if (root) {
        arr.push(root.val);
        preorderTraversal(root.left, arr);
        preorderTraversal(root.right, arr);
    }
    return arr;
};

中序和后序把上面if里面的三行代码调换顺序即可。
思路是一样的,借用JS的特性变得更精简一些。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants