Leetcode Solution Python 3 Math