Leetcode Time Limit Exceeded In Leetcode Python