注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
分享一个挂经,想让大家帮帮出出主义。目的是越走越好,越来越会做题。
我是nuna的一个online assessment,在hackeranke上做的。都是靠自己写,没有test cases,没有提示function怎么写。
Prune tree:
Given a tree(N-ary) and a set, prune the tree such as:
1. make sure all the nodes in set still exists in the tree
2. every node left on the tree has its siblings.
3. minimized the tree nodes.
Nodes in the set are guaranteed to be found in the tree.
Write code to meet the conditions:
var1. I保留”。parent的话本身是另外一个recursion
最后重新generate一个新的树,过滤掉不保留的。
var1: 在bfs中,如果发现不同层,保留之前的 (保留层级低的)
var2: 在bfs中,如果同一层,预先看那一个node有多少siblings。保留siblings少的。
我自己定义的树形不光有children list,还有状态,还有一个指向parent的指针。
要是可以的话,希望同求米和solution。
|