source code of leetcode - Python