http://leetcode.com/onlinejudge#question_24