leetcode submission 8 with test case