previous writtern code for leetcode