总结了所有看到的面经, 希望下周一电面好运,是一个去年入职的国人小姐姐面试我,希望不要刁难。
电面面经:
Numbers to letters 28 =>AB
Reorgnized string leetcode 767
Number of island 200
就是说一个矿,里面有0有1,给你rowIndex和colIndex,
挖到0就0本身被摧毁,挖到1除了1本身被摧毁之外还要
向上下左右4个方向继续摧毁。最后返回一共摧毁了多少个矿坑。
Reorganize String 767
Excel Sheet Column Number 171
Excel Sheet Column Title 168
Valid Tic-Tac-Toe State 794
Isomorphic Strings 205
Word break 139
Onsite 面经
Word search 79
follow up1: 可以斜着走
follow up2: 给一个字典,要找出所有字典里的单词,问怎样预处理字典(word search II 用trie tree)
Game of Life 289
Diagonal Traverse 498
Valid Parentheses {} () [] //
Merge Intervals 56
Cousins in Binary Tree 993.
Debug
static class Node{
int val;
Node left;
Node right;
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
}
//buggy one
public void reorder(Node node) {
if(node == null) {
return;
}
if((node.left == null || node.left != null && node.left.getVal() < node.getVal())
&& (node.right == null || node.right != null && node.right.getVal() < node.getVal())
) {
return;
}
Node max = node.left;
if(node.left == null) {
max = node.right;
// coding bug here(first)
}else if(node.left.val < node.right.val) {
max = node.right;
}
// coding bug here(second)
max.setVal(node.getVal());
node.setVal(max.getVal());
// algorithm bug here(3rd)
reorder(node.right);
reorder(node.left);
}
//correct one
public void reorder2(Node node) {
if(node == null) {
return;
}
if((node.left == null || node.left != null && node.left.getVal() < node.getVal())
&& (node.right == null || node.right != null && node.right.getVal() < node.getVal())
) {
return;
}
reorder2(node.right);
reorder2(node.left);
Node max = node.left;
if(node.left == null) {
max = node.right;
}else if(node.right != null && node.left.val < node.right.val) {
max = node.right;
}
int temp = max.getVal();
max.setVal(node.getVal());
node.setVal(temp);
reorder2(node.right);
reorder2(node.left);
reorder(right);
reorder(left);
}
public static void main(String[] args) {
}
}