Solution of leetcode OJ