Mar 19, 2017
["Java"]

Recently I am study the concurrent concept on Java. And I wrote a demo code to help understand how `ExecutorService` works.
Read more...

Feb 04, 2017
["Algorithm", "Leetcode"]

用三种不同的方法解[483 Smallest Good Base](https://leetcode.com/contest/leetcode-weekly-contest-16b/problems/smallest-good-base/). For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a string representing n, you should return the smallest good base of n in string format.
Read more...

Feb 01, 2017
["Algorithm", "Leetcode"]

一道有意思的题目, 用到了异或运算的一个小特性. [LeetCode 421 Maximum XOR of Two Numbers in an Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/). Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do this in O(n) runtime?
Read more...

Jan 28, 2017
["Algorithm", "Leetcode"]

[LeetCode 4 Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/). There are two sorted arrays nums1 and nums2 of size m and n respectively.There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). LeetCode 中第一道Hard难度的题目, 做了好几遍, 还是不能bug-free一遍过.
Read more...

Jan 18, 2017
["Algorithm"]

[LeetCode 480 Sliding Window Median](https://leetcode.com/problems/sliding-window-median/) 这题真是丧心病狂! 找中位数当然用Heap或者Balanced BST了, 然后Sliding Window当然需要支持Delete操作了. 好吧, 在Python中并没有自带的能同时支持两者的数据结构. 因此, 想在`O(N logK)`的时间复杂度里面实现Sliding Window Median, 只能自己写一个数据结构了. 本文实现了Python中的Hash Heap数据结构, 并且附带简单的测试函数.
Read more...

Jan 17, 2017
["Algorithm", "Leetcode"]

You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand. Each time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if there is a group of 3 or more balls in the same color touching, remove these balls. Keep doing this until no more balls can be removed. Find the minimal balls you have to insert to remove all the balls on the table.
Read more...

Dec 19, 2016
["Algorithm"]

While reading the article in [GeeksForGeeks about the Floyd-Warshall Algorithm](http://www.geeksforgeeks.org/dynamic-programming-set-16-floyd-warshall-algorithm/), I got little confused about the correctness of this algorithm, wondering why it works. After spending some time understanding it and search the proof about this algorithm, now I understand why the `k` loop should be the out-est loop in the algorithm. Here is some explanation for this algorithm where [GeeksForGeeks about the Floyd-Warshall Algorithm](http://www.geeksforgeeks.org/dynamic-programming-set-16-floyd-warshall-algorithm/) didn't explain well.
Read more...