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

2022-10-21 #84

Open
github-actions bot opened this issue Oct 20, 2022 · 2 comments
Open

2022-10-21 #84

github-actions bot opened this issue Oct 20, 2022 · 2 comments

Comments

@github-actions
Copy link

No description provided.

@gongpeione
Copy link
Contributor

145 Binary Tree Postorder Traversal

/*
 * @lc app=leetcode id=145 lang=typescript
 *
 * [145] Binary Tree Postorder Traversal
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * class TreeNode {
 *     val: number
 *     left: TreeNode | null
 *     right: TreeNode | null
 *     constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.left = (left===undefined ? null : left)
 *         this.right = (right===undefined ? null : right)
 *     }
 * }
 */
function postorderTraversal(root: TreeNode | null): number[] {
    const ans = [];

    const walk = (node) => {
        node?.left && walk(node.left);
        node?.right && walk(node.right);

        node?.val && ans.push(node.val);
    }

    walk(root);

    return ans;
};
// @lc code=end

Nickname: Geeku
From vscode-hzfe-algorithms

1 similar comment
@gongpeione
Copy link
Contributor

145 Binary Tree Postorder Traversal

/*
 * @lc app=leetcode id=145 lang=typescript
 *
 * [145] Binary Tree Postorder Traversal
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * class TreeNode {
 *     val: number
 *     left: TreeNode | null
 *     right: TreeNode | null
 *     constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.left = (left===undefined ? null : left)
 *         this.right = (right===undefined ? null : right)
 *     }
 * }
 */
function postorderTraversal(root: TreeNode | null): number[] {
    const ans = [];

    const walk = (node) => {
        node?.left && walk(node.left);
        node?.right && walk(node.right);

        node?.val && ans.push(node.val);
    }

    walk(root);

    return ans;
};
// @lc code=end

Nickname: Geeku
From vscode-hzfe-algorithms

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

No branches or pull requests

1 participant