算法第四版 1.2.6

题目:如果字符s中的字符循环移动任意位置之后可以得到另一个字符t,那么s就被t称为回环变位。例如:ACTGAC 就是 TGACAC的一个回环变位,反之亦然;

代码如下:

import edu.princeton.cs.algs4.StdOut;

public class No1_2_5 {
    public static void main(String[] args)
    {
        String s ="ACTGACG";
        String t = "TGACGAC";
        
        String temp = s+s;//s+s一定包含t。ACTGACGACTGACG
 if(temp.indexOf(t)!=-1) //返回t在temp中第一次出现的位置,只要有就一定不会返回-1;

  StdOut.println("true");

else
  StdOut.println(
"false");
}
}

猜你喜欢

转载自www.cnblogs.com/qinmin/p/12274639.html