小红每天都要背单词然后她会把每天记住了多少单词记录下来并在小红书上打卡。当小红背单词时如果她已经记住了 i 个单词且背了一个没有记住的新单词 i +1次则她就会记住这个新单词。例如当她按顺序背[ you thank thank ]时她第一次背单词 you 时她就能记住 you 。而由于她已经记住了一个单词所以需要背两次 thank 才能记住 thank 。现在你知道了小红背单词的顺序请你求出小
def countWords(words): count = 0 memory = set() for word in words: if word not in memory: memory.add(word) count += 1 return count
words = ["you", "thank", "thank"] result = countWords(words) print(result)
原文地址: https://www.cveoy.top/t/topic/iInl 著作权归作者所有。请勿转载和采集!