leetcode solution written in python