Count Distinct Substring Leetcode Python