solve 9 problem of leetcode