Solution to leetcode with python