solution to the online judgement of Leetcode.com