Skip to content

Latest commit

 

History

History
executable file
·
42 lines (27 loc) · 896 Bytes

m01.09.md

File metadata and controls

executable file
·
42 lines (27 loc) · 896 Bytes

题目描述

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

示例1:

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

示例2:

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

提示:

  • 字符串长度在[0, 100000]范围内。

说明:

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

class Solution {
    public boolean isFlipedString(String s1, String s2){
        //长度要一致
        if (s1.length() != s2.length()) {
            return false;
        }
        //而后,将字符串拼接,判断是否包含s1
        String ss = s2 + s2;
        return ss.contains(s1);
    }
}