code accepted by leetcode