IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    2020 第22周 LeetCode 记录

    Yiran\'s Blog发表于 2020-06-01 05:44:57
    love 0
    1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence 链接到标题 切分句子然后遍历判断是否为前缀,需要返回索引 + 1。 class Solution: def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: for idx, w in enumerate(sentence.split(' ')): if w.startswith(searchWord): return idx + 1 else: return -1 1456. Maximum Number of Vowels in a Substring of Given Length 链接到标题 滑动窗口,使用字典统计每个元音出现的次数,每次更新最大值。 class Solution: def maxVowels(self, s: str, k: int) -> int: d = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0} for c in s[:k]: if c in d: d[c] += 1 res = sum(d.


沪ICP备19023445号-2号
友情链接