leetcode submission 7 with test case