注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
BB面经
1. 325 Maximum Size Subarray Sum Equals K
2. Missing number, binary search(since it is ordered)
3. binary tree, get grandparent node value
TreeNode grandpa = null;
public int getGrandPa(TreeNode root) {
getParentValue(root, 2);
System.out.println(grandpa == null ? null : grandpa.val);
return -1;
}
private void getParentValue(TreeNode root, int node){
if(root == null || (root.left == null && root.right == null)){
return;
}
if(root.left.left == null && root.left.right == null && root.right.left == null && root.right.right == null){
return;
}
if(((root.left.left != null) && root.left.left.val == node) ||
(root.left.right != null && root.left.right.val == node) ||
(root.right.right != null && root.right.left.val == node) ||
(root.right.right != null && root.right.right.val == node)){
grandpa = root;
return;
}
getParentValue(root.left, node);
getParentValue(root.right, node);
}
helper(TreeNode child,TreeNode parent){
map.put(child, parent);
if(child.left != null){
helper(chiled.left, child);
}
if(child.right != null){
helper(child.right, child);
}
}
4. 跑马问题
一个max heap + hashmap存马和节点关系
5.岛屿周长问题(考到了)
dfs也行,islands * 4 - neighbours * 2
6.intersection of two array
7.unique value stack
LRU cache的思想,double linked list + hashmap
8.Find top 10 most frequent words in an array of strings.
bucket sort. bucket sort的思想就是把freq table generate出来以后,建立一个 buckets[],
map.put(n, map.getOrDefault(n, 0) + 1);
9.Coding: Given an input array, print the first longest substring with contiguous same
characters. (e.g. abbbc -> bbb, abbbcbb -> bbb)
sliding window
10.reverse integer, follow up: 小数怎么办,分开整呗
double value = 3.25;
double fractionalPart = value % 1;
double integralPart = value - fractionalPart;
整数换小数
private static double convert(int a){
int temp = a;
double i = 1 ;
while(a > 0){
i = i * 10;
a = a / 10;
}
return temp / i;
}
11. row){
System.out.print(array[r][c] + " ");
r++;
c--;
}
System.out.println();
}
for(int j = 1 ; j < row ; j++){
int r = j;
int c = col - 1;
while(r < row ){
System.out.print(array[r][c] + " ");
r++;
c--;
}
System.out.println();
}
}
32.soft reference, weak refenrence
33.魔方表面刷漆,拆成27个以后,拿一个向上扔,top是黑的概率(6* 1 + 8 * 3 + 12 * 2)/ 27 * 6
34.print linked list 从尾到头
printList(Listnode<E> llist) {
if (llist == null) {
return;
}
printList(llist.getNext());
System.out.println(llist.getData());
}
35.fibonacci递归和iterative
public int fibonacci(int n) {
if(n <= 1){
return 0;
}
return helper(n - 2, 1, 0);
}
private int helper(int n, int pre, int prepre){
if(n == 0){
return pre;
}
return helper(n - 1, pre + prepre , pre);
}
36.
two sum各种变形
1.没sort -> hashset
2.sort -> two pointers
3.有重复,就while loop 跳过重复,如果用的是two pointers
加油!
|