注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 匿名 于 2025-3-26 23:52 编辑
First round:
Given a binary tree, return the values of the outer nodes of the tree clockwise, starting from the root node, in a list. the outer nodes are: 1. nodes visible when you look from left or right of the tree, 2. leaf nodes (nodes with no child node)
I implemented 3 recursive functions to get left, bottom, and right nodes respectively, then combine them into one list. Special cases to handle: 1. ignore leaf nodes in both left f parentheses using ITERATIVE method. I can only think of the following method: iterate through number 0-2^(2n), each number bit 1 is ( and bit 0 is ). then filter invalid parentheses. Do you have a better approach? Please share it in comments.
求大米看面经 |