Power Of Three Leetcode Solution Python