【Python】【难度:简单】Leetcode 面试题 01.09. 字符串轮转

字符串轮转。给定两个字符串s1和s2,请编写代码检查s2是否为s1旋转而成(比如,waterbottle是erbottlewat旋转后的字符串)。

示例1:

 输入:s1 = "waterbottle", s2 = "erbottlewat"
 输出:True
示例2:

 输入:s1 = "aa", "aba"
 输出:False
提示:

字符串长度在[0, 100000]范围内。
说明:

你能只调用一次检查子串的方法吗?

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/string-rotation-lcci
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

class Solution(object):
    def isFlipedString(self, s1, s2):
        """
        :type s1: str
        :type s2: str
        :rtype: bool
        """
        return len(s1)==len(s2) and s2 in s1*2

执行结果:

通过

显示详情

执行用时 :24 ms, 在所有 Python 提交中击败了69.09%的用户

内存消耗 :13.3 MB, 在所有 Python 提交中击败了100.00%的用户

原创文章 105 获赞 0 访问量 1684

猜你喜欢

转载自blog.csdn.net/thomashhs12/article/details/106001201