摘要: 1 // Java Iterator interface reference: 2 // https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html 3 class PeekingIterator implements Iter 阅读全文
posted @ 2016-07-06 15:26 keepshuatishuati 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Use level + 1 to avoid traversal two rooms back and forth. 阅读全文
posted @ 2016-07-06 15:17 keepshuatishuati 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Remember: need to check whether has the word in hashset and garantee size is one. 阅读全文
posted @ 2016-07-06 14:33 keepshuatishuati 阅读(116) 评论(0) 推荐(0) 编辑
摘要: This is straight forward solution. 00 D <- D 10 L <- D 11 L <- L 01 D <- D So we need to differentiate 11 = 3 and 10 = 2 阅读全文
posted @ 2016-07-06 14:19 keepshuatishuati 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 1 public class Solution { 2 public boolean canWin(String s) { 3 if (s.length() result = new ArrayList(); 7 for (int i = 0; i < s.length() - 1; i++) { 8 if (s.cha... 阅读全文
posted @ 2016-07-06 14:10 keepshuatishuati 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 1 public class Solution { 2 public List generatePossibleNextMoves(String s) { 3 List result = new ArrayList(); 4 if (s.length() < 2) { 5 return result; 6 ... 阅读全文
posted @ 2016-07-06 09:39 keepshuatishuati 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 1 public class MedianFinder { 2 private PriorityQueue maxQueue; 3 private PriorityQueue minQueue; 4 5 public MedianFinder() { 6 maxQueue = new PriorityQueue(Collections... 阅读全文
posted @ 2016-07-06 07:40 keepshuatishuati 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 ... 阅读全文
posted @ 2016-07-06 07:33 keepshuatishuati 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Maximum value get should be count increase. Otherwise, it already breaks the consequences. 阅读全文
posted @ 2016-07-06 07:24 keepshuatishuati 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Binary search: 1. The bound is defined to search "0" or "1". When search 0 - x, we want to get the most left "1". So k < right mean there is a one, j 阅读全文
posted @ 2016-07-06 07:13 keepshuatishuati 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1 public class Solution { 2 private int count; 3 private int[] parent; 4 public List numIslands2(int m, int n, int[][] positions) { 5 List result = new ArrayList(); 6 ... 阅读全文
posted @ 2016-07-06 06:18 keepshuatishuati 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Binary index tree: https://www.topcoder.com/community/data-science/data-science-tutorials/binary-indexed-trees/ 阅读全文
posted @ 2016-07-06 06:00 keepshuatishuati 阅读(194) 评论(0) 推荐(0) 编辑
摘要: lastSell = sell is after buy max. So the buy price is compared with sell[i-2]. Current sell is sell[i-1]. 阅读全文
posted @ 2016-07-06 05:43 keepshuatishuati 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 1. Check boundary case that when n == 1. There is only one node (0) 2. Set can access by iterator. 阅读全文
posted @ 2016-07-06 05:30 keepshuatishuati 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 1. Make final balloon as the position i. 2. try to optimize the solution from (left , i - 1) to (i + 1, right). 3. Since it garantee to cover i positi 阅读全文
posted @ 2016-07-06 05:15 keepshuatishuati 阅读(137) 评论(0) 推荐(0) 编辑