摘要:
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l 阅读全文
摘要:
code 不难,multi dimension array 的求 summation。 之前准备地里的LinkedIn高频题一个没碰到。。。 /** Suppose you are given a class that implements a k-dimensional array * interface and you want to perform an operation that ... 阅读全文
摘要:
public static int LPS(int[] a) { int[][] dp = new int[a.length][a.length]; for (int i = 0; i = 0; i--) { for (int j = i + 1; j < dp.length; j++) { if (a[i] == a[j]) { dp[i][j] = dp[... 阅读全文
摘要:
import java.util.*; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class BlockQueue { public int cap... 阅读全文
摘要:
import java.util.*; import java.util.concurrent.locks.*; public class H2O { private int HCount = 0; private int OCount = 0; private Lock lock = new ReentrantLock(); private Condition condH = lo... 阅读全文
摘要:
第一道是设计一个有选择性的iterator,类型T。面试官给的API里有一个自定selector,selector里有差不多叫boolean isOK(T t)方法。设计一个iterator每次调用hasNext(),返回接下来是否能取到合格的T对象;每次调用next(),返回下一个合格的T对象。我 阅读全文
摘要:
public class MidStack { static class Node{ T val; Node next = null; Node pre = null; public Node(T val){ this.val = val; } } private int size = 0; private Node head = null; privat... 阅读全文
摘要:
这道题要求in-place做法,不能使用extra space, 那么,做法跟Rotate Array那道题非常相似 (1)reverse the whole array (2)reverse each subarray seperated by ' ' 注意不要忘了reverse最后一个word 阅读全文
摘要:
/* Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and b... 阅读全文