Topic: String rotation. Given two strings s1 and s2, write code to check that S2 is rotated by S1 (for example, waterbottle is rotated by Erbottlewat). Example 1: Input: s1 = "waterbottle", s2 = "erbottlewat" Output: True Example 2: Input: s1 = "AA ", s2 =" ABA "Output: False Warning: The string is within the range of 0, 100000. Description: Can you call the method that checks substrings only once? Contans (s1) is rotated if it is true, otherwise it is not rotated, pay attention to the judgment of lengthCopy the code

1. Isflipedstring.java:

package com.yuhl.right.leetcode;

/ * * *@author yuhl
 * @Date2020/10/25 consecrate *@Classname IsFlipedString
 * @DescriptionString rotation * String rotation. Given two strings s1 and s2, write code to check that S2 is rotated by S1 (for example, waterbottle is rotated by Erbottlewat). * * Example 1: * Input: s1 = "waterbottle", s2 = "erbottlewat" * Input: s1 = "AA ", s2 =" ABA "* Output: False * Hint: * The string is in the range of [0, 100000]. * Description: * Can you call the method that checks the substring only once? * /
public class IsFlipedString {
    public static void main(String[] args) {
        String s1 = "waterbottle";
        String s2 = "erbottlewat";
        boolean flipedString = isFlipedString(s1, s2);
        System.out.println(flipedString);
    }

    public static boolean isFlipedString(String s1, String s2) {
        Contans (s1) is rotated if it is true; otherwise, it is not rotated
        if(s1.length() ! = s2.length())return false;
        if((s2+s2).contains(s1)){
            return true;
        }else{
            return false; }}}Copy the code

2. Execution Results:

"C: \ Program Files \ Java \ jdk1.8.0 _201 \ bin \ Java exe" 
true
Copy the code