代码拉取完成,页面将自动刷新
# Time: O(n + s), n is the sum of all word lengths, s is the length of S
# Space: O(l + s), l is the max word length
import itertools
class Solution(object):
def expressiveWords(self, S, words):
"""
:type S: str
:type words: List[str]
:rtype: int
"""
# Run length encoding
def RLE(S):
return itertools.izip(*[(k, len(list(grp)))
for k, grp in itertools.groupby(S)])
R, count = RLE(S)
result = 0
for word in words:
R2, count2 = RLE(word)
if R2 != R:
continue
result += all(c1 >= max(c2, 3) or c1 == c2
for c1, c2 in itertools.izip(count, count2))
return result
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。