美文网首页
字符串轮转

字符串轮转

作者: 六寸光阴丶 | 来源:发表于2020-04-12 11:04 被阅读0次

    问题描述

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

    示例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;
            }
            String ss = s2 + s2;
            return ss.contains(s1);
        }
    }
    

    相关文章

      网友评论

          本文标题:字符串轮转

          本文链接:https://www.haomeiwen.com/subject/darvmhtx.html