LeetCode题解(0796):旋转字符串(Python)
发布日期:2021-06-29 19:54:18 浏览次数:2 分类:技术文章

本文共 621 字,大约阅读时间需要 2 分钟。

题目:(简单)

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N ) O(N) O(N) O ( N ) O(N) O(N) 24ms (100.00%)
Ans 2 (Python)
Ans 3 (Python)

LeetCode的Python执行用时随缘,只要时间复杂度没有明显差异,执行用时一般都在同一个量级,仅作参考意义。

解法一:

在这里插入图片描述

def rotateString(self, A: str, B: str) -> bool:    if len(A) == 0 and len(B) == 0:        return True    elif len(A) == 0 or len(B) == 0:        return False    b = B[0]    if b not in A:        return False    start = 0    while start < len(A):        s = A[start:]        if b not in s:            break        idx = s.index(b) + start        if B == A[idx:] + A[0:idx]:            return True        start = idx + 1    return False

转载地址:https://dataartist.blog.csdn.net/article/details/107076058 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode题解(0804):摩斯密码不同的单词(Python)
下一篇:LeetCode题解(0788):进制转换的奇技淫巧

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月19日 21时22分04秒