用惯了android现在特别讨厌实体键# PDA - 掌中宝
l*i
1 楼
面了1小时15分,前几题感觉不错,结果被问到tcp vs udp的时候根本不知道是啥玩意
儿,估计是悲催了。哎,题目如下:
1.Can you talk a little about yourself first?
2.Why do you choose p?
3.Difference between linkedlist and array
4.In what condition do you use tree structure? How do you keep them balanced?
5.TCP protocol vs UDP protocol (have no idea)
6.How do you implement a hash table?
following up question:
Data structure; size; hashfunction; linkedlist vs hashtable in dealing with
collision
7.coding
print spiral matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of
the matrix in spiral order.
For example,
Given the following matrix:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
You should return [1,2,3,6,9,8,7,4,5].
coding题目挺简单的,听完题马上想到思路。我先说了一下思路,对方说可以。然后让
我说说代码的结构。我不知道该怎么答,就码了几个变量并解释他们是干什么的。感觉
对方似乎不是很满意。在写代码的时候面试官总是让我停下来解释怎么回事。根本没时
间检查bug。最后我用个例子,放到代码里一行一行地解释怎么回事,讲了半天对方才
肯定我的code会work.讲完后我试探地说“i'm sure you probably have other
solutions", 面试官说是。
面完后搜了下才知道是leetcode上的题,面试官估计是有更优解。
-----------------------------
上spiral matrix的代码,请码友们多多批评指教~
//java
public void printSpiral(int[][] numbers) {
int direction =0;//if 0 go right, if 1 go down, if 2 go left, if 3 go up
int row=0, column=0;
while(numbers[row][column]!=Integer.MIN_VALUE){
System.out.print(numbers[row][column]);
numbers[row][column]=Integer.MIN_VALUE;
int nextrow=nextrow(direction, row);
int nextcolumn=nextcolumn(direction, column);
if (!isValid(numbers, nextrow, nextcolumn)) {
nextrow=nextrow(direction, row);
nextcolumn=nextcolumn(direction, column);
if (!isValid(numbers, nextrow, nextcolumn)) break;
}
row = nextrow;
column=nextcolumn;
}
}
int nextrow(int direction, int row){
if (direction==0){//moving left
return row;
}
else if (direction==1){//moving down
return row+1;
}
else if (direction==2){//moving right
return row;
}
else {//moving up
return row-1;
}
}
int nextcolumn(int direction, int column){
if (direction==0){//moving left
return column+1;
}
else if (direction==1){//moving down
return column;
}
else if (direction==2){//moving right
return column-1;
}
else {//moving up
return column;
}
}
boolean isValid(int [][]numbers, int nextrow, int nextcolumn){
return (nextrow<0||
nextrow>numbers.length-1||
nextcolumn<0||nextcolumn>numbers[0].length||
numbers[nextrow][nextcolumn]==Integer.MIN_VALUE)?false: true;
}
儿,估计是悲催了。哎,题目如下:
1.Can you talk a little about yourself first?
2.Why do you choose p?
3.Difference between linkedlist and array
4.In what condition do you use tree structure? How do you keep them balanced?
5.TCP protocol vs UDP protocol (have no idea)
6.How do you implement a hash table?
following up question:
Data structure; size; hashfunction; linkedlist vs hashtable in dealing with
collision
7.coding
print spiral matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of
the matrix in spiral order.
For example,
Given the following matrix:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
You should return [1,2,3,6,9,8,7,4,5].
coding题目挺简单的,听完题马上想到思路。我先说了一下思路,对方说可以。然后让
我说说代码的结构。我不知道该怎么答,就码了几个变量并解释他们是干什么的。感觉
对方似乎不是很满意。在写代码的时候面试官总是让我停下来解释怎么回事。根本没时
间检查bug。最后我用个例子,放到代码里一行一行地解释怎么回事,讲了半天对方才
肯定我的code会work.讲完后我试探地说“i'm sure you probably have other
solutions", 面试官说是。
面完后搜了下才知道是leetcode上的题,面试官估计是有更优解。
-----------------------------
上spiral matrix的代码,请码友们多多批评指教~
//java
public void printSpiral(int[][] numbers) {
int direction =0;//if 0 go right, if 1 go down, if 2 go left, if 3 go up
int row=0, column=0;
while(numbers[row][column]!=Integer.MIN_VALUE){
System.out.print(numbers[row][column]);
numbers[row][column]=Integer.MIN_VALUE;
int nextrow=nextrow(direction, row);
int nextcolumn=nextcolumn(direction, column);
if (!isValid(numbers, nextrow, nextcolumn)) {
nextrow=nextrow(direction, row);
nextcolumn=nextcolumn(direction, column);
if (!isValid(numbers, nextrow, nextcolumn)) break;
}
row = nextrow;
column=nextcolumn;
}
}
int nextrow(int direction, int row){
if (direction==0){//moving left
return row;
}
else if (direction==1){//moving down
return row+1;
}
else if (direction==2){//moving right
return row;
}
else {//moving up
return row-1;
}
}
int nextcolumn(int direction, int column){
if (direction==0){//moving left
return column+1;
}
else if (direction==1){//moving down
return column;
}
else if (direction==2){//moving right
return column-1;
}
else {//moving up
return column;
}
}
boolean isValid(int [][]numbers, int nextrow, int nextcolumn){
return (nextrow<0||
nextrow>numbers.length-1||
nextcolumn<0||nextcolumn>numbers[0].length||
numbers[nextrow][nextcolumn]==Integer.MIN_VALUE)?false: true;
}