leetcode submission 6 with test case