java answer for http://oj.leetcode.com