求两个字符串中的最大相同子串 SubString

package com.itcast.base;

public class SubStringTest {
 public static void main(String[] args) {
  String str1 = "ashfjeudccckfjgiccccccjgurhd";
  String str2 = "dhfurjcccckgoymjdhccfi";
  
  String max = "";
  for (int i = 0; i < str2.length(); i++) {
   String temp1 = str2.substring(i);
//   System.out.println("temp1:" + temp1);
   for (int j = temp1.length() - 1; j >= 0; j--) {
    String temp2 = temp1.substring(0, j);
//    System.out.println("temp2:" + temp2);
    if (str1.indexOf(temp2) != -1 && temp2.length() > max.length()) {
     max = temp2;
    }
   }
  }
  System.out.println("max:" + max);
 }
}

上一篇:内网FTP服务器架设不完全解析


下一篇:云原生时代 RocketMQ 运维管控的利器 - RocketMQ Operator