0
点赞
收藏
分享

微信扫一扫

旋转词---

舟海君 2022-03-21 阅读 44

题目:给定俩个字符串s1和s2,要求判定s2是否能够被通过s1作循环移位(rotate)得到的字符串包含。例如,给定s1 = AABCD和s2=CDAA,返回true;给定s1=ABCD和s2 = ACBD,返回true。

import javax.sound.sampled.EnumControl;
import java.sql.Array;
import java.util.*;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String strA = input.nextLine();
        String strB = input.nextLine();
        System.out.println(isContain(strA,strB));
    }
    public static boolean isContain(String strA,String strB){
        int n = strA.length();
        StringBuffer sb = new StringBuffer(strA);
        sb.append(strA);
        boolean res = false;
        for(int i =0;i<n;i++){
            if(sb.substring(i,i+n).indexOf(strB) != -1){
                res = true;
                break;
            }
        }
        return res;
    }

}
举报

相关推荐

0 条评论