leetcode submission 3 with test case