leetcode/lcci/01.09.String Rotation
yanglbme 86f2708dba feat: add python and java solutions to lcci problem: 01.09.String Rotation
添加《程序员面试金典》题解:01.09.字符串轮转
2020-07-28 20:00:31 +08:00
..
README.md feat: add python and java solutions to lcci problem: 01.09.String Rotation 2020-07-28 20:00:31 +08:00
README_EN.md feat: add python and java solutions to lcci problem: 01.09.String Rotation 2020-07-28 20:00:31 +08:00
Solution.java feat: add python and java solutions to lcci problem: 01.09.String Rotation 2020-07-28 20:00:31 +08:00
Solution.py feat: add python and java solutions to lcci problem: 01.09.String Rotation 2020-07-28 20:00:31 +08:00

README_EN.md

01.09. String Rotation

中文文档

Description

Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 (e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another?

Example 1:


Input: s1 = "waterbottle", s2 = "erbottlewat"

Output: True

Example 2:


Input: s1 = "aa", "aba"

Output: False

 

Note:

  1. 0 <= s1.length, s1.length <= 100000

Solutions

Python3

class Solution:
    def isFlipedString(self, s1: str, s2: str) -> bool:
        return len(s1) == len(s2) and s1 in (s2 * 2)

Java

class Solution {
    public boolean isFlipedString(String s1, String s2) {
        return s1.length() == s2.length() && (s2 + s2).indexOf(s1) != -1;
    }
}

...