h**********w 发帖数: 39 | 1 周五的电面
网投简历,一周后hr一轮电面,就是list一堆题网上都有,udp tcp区别,ssl,linux
命令,bit的简单题,match关键字即可
然后电面,之前大概看了一下glassdoor和本版的面经,电面的时候一个都没命中:为
什么投yelp,简历上的project,多重继承,ood
最后15分钟coding
一个树: food
/ / \ \
america, china, mexico, indian
/ \
mifan, mianshi
/ \
jiaozi baozi
要求先设计树的数据结构,然后任意给一个string,比如mianshi(面食) 返回饺子和包
子,如果给china,返回mifan,jiaozi和baozi, 就是返回一个child下的全部叶子
当时脑子抽了写了个bfs,先在root找node,然后再遍历node的叶子,找不到就 null,
其实应该recur的。上来直接就写了,最后发现其实找node的同时就可以把node往
result里插了,功能有dup,然后题目沟通的也不是很好,果断坐等据信
虽然是三哥面的,口音我有点不太习惯,但是总体来说还挺不错,也没刁难我,自己做
题做的不够活,题目没沟通好就开始写,跪的心服口服 | t******f 发帖数: 79 | | J**9 发帖数: 835 | 3 N-ary tree
typedef struct tree_node {
char *data;
int numChildren;
struct tree_node **children;
} treeNode;
search by pre-order traversal:
treeNode *searchNode(treeNode *root, char *data)
{
if (!root || !data) return NULL;
if (!strcmp(root->data, data))
return root;
for (int i=0; inumChildren;i++)
{
treeNode *node = searchNode(root->children[i], data);
if (node)
return node;
}
return NULL;
} | h**********w 发帖数: 39 | 4 不是很懂。。不过感觉好像返回了一个node?
贴一个我的
/*
public class TreeNode{
public String name = null;
public ArrayList child =null;
public TreeNode(String name){
this.name = name;
child = new ArrayList ();
}
}
*/
public void find(TreeNode root, String name, ArrayListtmp){
if(root.name == name){
for(TreeNode s :root.child){
tmp.add(s);
}
return;
}
if(root.child.size()>0){
for(TreeNode s : root.child){
find(s,name,tmp);
}
}
}
【在 J**9 的大作中提到】 : N-ary tree : typedef struct tree_node { : char *data; : int numChildren; : struct tree_node **children; : } treeNode; : search by pre-order traversal: : treeNode *searchNode(treeNode *root, char *data) : { : if (!root || !data) return NULL;
| J**9 发帖数: 835 | 5 It's trivial to print all children once you get the node.
【在 h**********w 的大作中提到】 : 不是很懂。。不过感觉好像返回了一个node? : 贴一个我的 : /* : public class TreeNode{ : public String name = null; : public ArrayList child =null; : public TreeNode(String name){ : this.name = name; : child = new ArrayList (); : }
| z***2 发帖数: 66 | 6 這樣寫對嗎?
class Solution {
ArrayList result;
public TreeNode(TreeNode root,String name){
result= new ArrayList();
recur(root,name,false);
return result;
}
public void recur(TreeNode node, String name, boolean record){
if(node !=null){
if(record){
result.add(node.val);
}
if(node.val=name){
recur(node.left,name,true);
recur(node.right,name,true);
}
else{
recur(node.left,name,record);
recur(node.right,name,record);
}
}
}
} | h**********w 发帖数: 39 | 7 嗯,找到node以后不是print他全部的children,而是print全部leaf nodes, 所以可能
还要recur几层
当然这个确实也没啥难度
【在 J**9 的大作中提到】 : It's trivial to print all children once you get the node.
| h**********w 发帖数: 39 | 8 好像不对,他那个树有可能有100个child,而且你这个把所有的child都算进去了,要
叶子节点
【在 z***2 的大作中提到】 : 這樣寫對嗎? : class Solution { : ArrayList result; : public TreeNode(TreeNode root,String name){ : result= new ArrayList(); : recur(root,name,false); : return result; : } : : public void recur(TreeNode node, String name, boolean record){
| z***2 发帖数: 66 | 9 看錯了題目 >< , 這下應該對了
class Solution {
ArrayList result;
public TreeNode(TreeNode root,String name){
result= new ArrayList();
recur(root,name,false);
return result;
}
public void recur(TreeNode node, String name, boolean record){
if(node !=null){
if(record){
if(node.left==null && node.right ==null){
result.add(node.val);
}
}
if(node.val=name){
recur(node.left,name,true);
recur(node.right,name,true);
}
else{
recur(node.left,name,record);
recur(node.right,name,record);
}
}
}
}
【在 h**********w 的大作中提到】 : 好像不对,他那个树有可能有100个child,而且你这个把所有的child都算进去了,要 : 叶子节点
| c*****a 发帖数: 808 | | | | H******9 发帖数: 8087 | 11 呵呵,分享下
linux
【在 h**********w 的大作中提到】 : 周五的电面 : 网投简历,一周后hr一轮电面,就是list一堆题网上都有,udp tcp区别,ssl,linux : 命令,bit的简单题,match关键字即可 : 然后电面,之前大概看了一下glassdoor和本版的面经,电面的时候一个都没命中:为 : 什么投yelp,简历上的project,多重继承,ood : 最后15分钟coding : 一个树: food : / / \ \ : america, china, mexico, indian : / \
| h*******0 发帖数: 270 | 12 为什么要把所以东西都写道一个函数里面呢? 为什么不先找node,然后在打印该node
下的所有leaf呢? 你这个drawback是每次都要遍历所有的点。 其实有些情况是不需要
遍历所有点的。
【在 z***2 的大作中提到】 : 看錯了題目 >< , 這下應該對了 : class Solution { : ArrayList result; : public TreeNode(TreeNode root,String name){ : result= new ArrayList(); : recur(root,name,false); : return result; : } : : public void recur(TreeNode node, String name, boolean record){
| x*****0 发帖数: 452 | | n********r 发帖数: 102 | | a*********0 发帖数: 2727 | 15 这题每层内容都是固定的,直接建个每层的索引不就完了。 比如一给哪国的食品,直
接从第二层搜索 | l*****a 发帖数: 14598 | 16 这是给的条件吗?
【在 a*********0 的大作中提到】 : 这题每层内容都是固定的,直接建个每层的索引不就完了。 比如一给哪国的食品,直 : 接从第二层搜索
|
|