count prefix of a given string leetcode