Consider the string s to be the infinite wraparound string of “abcdefghijklmnopqrstuvwxyz”, so s will look like this: “…zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd….”.
Now we have another string p. Your job is to find out how many unique non-empty substrings of p are present in s. In particular, your input is the string p and you need to output the number of different non-empty substrings of p in the string s.
Note: p consists of only lowercase English letters and the size of p might be over 10000.
Example 1:
Example 2:
Example 3:
解法1:
又是维护一个running local optimal,然后再更新最终答案的题目。
这里是把p中以每一个字符结尾的最长子串加入到hashmap中。
之后再得出一个加和就可以了。
C++
Java