- 博客(160)
- 收藏
- 关注
原创 new group contact
之前的做法有bugpublic class NewGroupContact { //http://www.fgdsb.com/2015/01/25/group-contacts/ // http://www.1point3acres.com/bbs/thread-148422-1-1.html // http://www.1point3acres.com/bbs/forum.php?mo
2016-08-31 19:52:57 846
原创 task schedule
private String schedule11(int [] array, int recover) { Map map = new HashMap<>(); int time = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length
2016-08-31 04:13:30 332
原创 无畏而煨,前行不止
今天得去公司,为了今天的复习计划和公司的事务,现在得先睡了。system design,要看的太多,要学的太多,要准备的太多,都是以前的欠账。无畏而煨,前行不止。
2016-08-29 19:47:22 863
原创 睡眠枪
半小时前,看system design实在是困了,想睡,等躺下,却如何也睡不着了,遂重新起身,喝罐红牛,system design。如果有一把机器猫中的睡眠枪该多好!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2016-08-29 13:10:11 560
转载 Scaling Memcache at Facebook
备忘,很好的总结笔记,https://zhuanlan.zhihu.com/p/21362291http://www.it610.com/article/1254147.htm
2016-08-28 13:46:26 763
原创 print list Reversely
private static void printReversely (ListNode node) { if (node.next != null) { printReversely(node.next); } System.out.println(node.data); }
2016-08-25 12:01:59 387
原创 Find Celebrity II
给你一个set 然后给你了个compareTo的方法,可以比较出大小(任意两个objects都能比较出大小,但是这种关系不具有传递性,即A>B,B>C但是A不一定大于C),让你找出set中最大的object,如果不存在,就返回null。 int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString
2016-08-25 11:38:51 284
原创 Kth Smallest element
private int quickSelect(int[] arr, int k) { int from = 0, to = arr.length - 1; while (from < to) { int l = from, r = to; int mid = arr[l + (r - l)/2]; while (l < r) { if (arr[l] >= mi
2016-08-25 11:28:57 285
原创 求连续K个数的和最大
public int getMaxSumKElements2(int[] nums, int k) { if (nums.length < k) { return -1; } int curMax = 0, curSum = 0; for (int i = 0; i < k; i++) { curSum += nums[i]; } curMax = curSum
2016-08-25 11:27:59 1233
原创 还有太多的想看想学想准备
连续看了13个小时的system design,感觉上次是看开始看薄了,而这13个小时,是又彻底看厚了,还有太多的想看想学想准备。。。接下来至少还有4个大的专题,还要复习大量的coding,那这下周二的决战还能ready吗。。。。。。。
2016-08-24 19:41:49 285
原创 Remove Duplicates from Sorted Array II
public class Solution { public int removeDuplicates(int[] nums) { if (nums.length < 3) { return nums.length; } int prev = 1, cur = 2; while (cur < nums.
2016-08-23 09:45:38 227
原创 Remove Duplicates from Sorted Array
public class Solution { public int removeDuplicates(int[] nums) { if (nums == null) { return 0; } int index = 0; for (int i = 1; i < nums.length; i++) {
2016-08-23 09:44:44 171
原创 Walls and Gates
public class Solution { public void wallsAndGates(int[][] rooms) { if (rooms == null || rooms.length == 0 || rooms[0].length == 0) { return; } Queue queue = new
2016-08-23 09:43:50 250
原创 Populating Next Right Pointers in Each Node II
/** * Definition for binary tree with next pointer. * public class TreeLinkNode { * int val; * TreeLinkNode left, right, next; * TreeLinkNode(int x) { val = x; } * } */public class
2016-08-23 08:19:02 215
原创 Course Schedule II
public class Solution { public int[] findOrder(int n, int[][] edges) { int[] courses = new int[n]; for (int i = 0; i < edges.length; i++) { courses[edges[i][0]]++;
2016-08-23 08:18:15 224
原创 H-Index II
public class Solution { public int hIndex(int[] citations) { int n = citations.length; if (n == 0) { return 0; } int min = 0, max = n - 1; while
2016-08-23 08:17:28 214
原创 Maximal Square
public class Solution { public int maximalSquare(char[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return 0; } int r = mat
2016-08-23 08:16:27 204
原创 Reverse Nodes in k-Group
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode reve
2016-08-23 06:46:30 230
原创 H-Index
public class Solution { public int hIndex(int[] citations) { Arrays.sort(citations); int h = 0; for (int i = 0; i < citations.length; i++) { int curH = Math.min
2016-08-23 06:45:48 308
原创 Maximal Rectangle
public class Solution { public int maximalRectangle(char[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return 0; } int r =
2016-08-23 06:45:00 220
原创 Palindrome Linked List
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public boolean isPal
2016-08-23 06:44:03 202
原创 Lowest Common Ancestor of a Binary Search Tree
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null) { return null; } else if (p.val > root.val && q.val > root.val) {
2016-08-23 04:12:12 246
原创 Increasing Triplet Subsequence
public class Solution { public boolean increasingTriplet(int[] nums) { if (nums == null || nums.length < 3) { return false; } int fmin = Integer.MAX_VALUE, smin
2016-08-23 04:11:30 200
原创 Meeting Rooms
/** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int e) { start = s; end = e; } * } */
2016-08-23 04:10:59 232
原创 Binary Tree Level Order Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {
2016-08-23 04:10:20 201
原创 Flatten Nested List Iterator
public class NestedIterator implements Iterator { Queue queue = null; public NestedIterator(List nestedList) { queue = new LinkedList<>(); build(nestedList); } pr
2016-08-23 03:40:32 217
原创 Kth Largest Element in an Array
public class Solution { public int findKthLargest(int[] nums, int k) { PriorityQueue q = new PriorityQueue<>(); for (int n: nums) { if (q.size() < k) {
2016-08-23 03:39:45 178
原创 Pow(x, n)
public class Solution { public double myPow(double x, int n) { if (n < 0) { return 1/pow(x, -n); } else { return pow(x, n); } } private
2016-08-23 03:38:59 197
原创 Search in Rotated Sorted Array
public class Solution { public int search(int[] A, int target) { if (A == null || A.length == 0) { return -1; } int left = 0, right = A.length - 1; while (le
2016-08-23 03:38:02 210
原创 Implement Trie (Prefix Tree)
public class Trie { class TrieNode { boolean isExisted; TrieNode[] children = new TrieNode[26]; } TrieNode root = null; public Trie() { root = new TrieNod
2016-08-22 07:28:46 166
原创 Merge Sorted Array
public void merge(int A[], int m, int B[], int n) { int ia = m - 1, ib = n - 1, i = m + n - 1; while (ia >= 0 && ib >= 0) { if (A[ia] > B[ib]) { A[i--] = A[
2016-08-22 07:27:53 156
原创 Valid Parentheses
public class Solution { public boolean isValid(String s) { if (s == null || s.length() % 2 == 1) { return false; } Stack stack = new Stack<>(); for (int
2016-08-22 07:26:33 157
原创 Sqrt(x)
public class Solution { public int mySqrt(int x) { long i = 0; long j = x/2 + 1; while (i <= j) { long mid = i + (j-i)/2; if (mid*mid == x) {
2016-08-22 07:25:33 173
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人