Count Number Of Substrings Leetcode Python