【leetcode--30.串联所有单词的子串】

        有没有一样喜欢看示例的,,看题目就觉得很难懂。大致就是words要进行排列组合,返回s中所有包含这个排列组合的首标。

顺完逻辑蛮好懂的,应该不算困难题,只是不知道用什么模块实现。

class Solution:
    def findSubstring(self, s: str, words: List[str]) -> List[int]:
        if not s or not words: return []
        one_word = len(words[0])
        all_len = one_word * len(words)
        n = len(s)
        words = Counter(words)
        res = []
        for i in range(0, n-all_len+1):
            tmp = s[i:i+all_len]
            c_tmp = []
            for j in range(0, all_len, one_word):
                c_tmp.append(tmp[j:j+one_word])
            if Counter(c_tmp) == words:
                res.append(i)
        return res

相关推荐

  1. leetcode 30. 串联所有单词

    2024-06-07 10:32:03       48 阅读
  2. LeetCode 30. 串联所有单词

    2024-06-07 10:32:03       38 阅读
  3. LeetCode_30_困难_串联所有单词

    2024-06-07 10:32:03       19 阅读
  4. 30. 串联所有单词 —— LeetCode (python)

    2024-06-07 10:32:03       16 阅读
  5. leedcode串联所有单词

    2024-06-07 10:32:03       39 阅读
  6. 【算法题】30. 串联所有单词

    2024-06-07 10:32:03       32 阅读
  7. 面试经典题---30.串联所有单词

    2024-06-07 10:32:03       30 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-07 10:32:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-07 10:32:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-07 10:32:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-07 10:32:03       20 阅读

热门阅读

  1. 2-链表-61-相交节点-LeetCode160

    2024-06-07 10:32:03       8 阅读
  2. GaussDB 数据库的事务管理

    2024-06-07 10:32:03       8 阅读
  3. Python语言回归:深入探索与实战应用

    2024-06-07 10:32:03       10 阅读
  4. 8086 汇编笔记(十一):内中断

    2024-06-07 10:32:03       10 阅读
  5. OC和Swift的区别,发送消息和执行方法的区别

    2024-06-07 10:32:03       6 阅读
  6. AWS Load Balancer Controller 实践

    2024-06-07 10:32:03       8 阅读
  7. iOS查看、分离、合并库framework的架构

    2024-06-07 10:32:03       8 阅读
  8. 图论第5天

    2024-06-07 10:32:03       8 阅读
  9. WPF 按键图标缩放动画示例

    2024-06-07 10:32:03       8 阅读