leetcode-python 在一个长字符串中寻找子字符串的出现次数以及位置
code
S = 'xxxabcxxxxabcxxabcxxabc' search="xxxa" last_cur=0 count=0 while(1): where=S.find(search) if(not where==-1): print(last_cur+where) S=S[where+len(search):] last_cur=last_cur+where+len(search) count+=1 else: break print("总数为:",count)