[Python] 纯文本查看 复制代码
word=str.lower(input('Input a string to check if there\'s a/some repeated character(s).'))
REPEATED_CHARACTER=False
for n in range(len(word)):
if (word[n] in word[0:n]) or (word[n] in word[n+1:]):
print('有重复')
REPEATED_CHARACTER=True
break
else:
pass
if not REPEATED_CHARACTER:
print('无重复')
比如说这个例子,判断字符串内是否有重复字符,我实现的这个一看就很复杂,
但是它的时间复杂度具体是多少?O(n)甚至是O(n^2)?
|