閱讀857 返回首頁    go 阿裏雲 go 技術社區[雲棲]


求兩個字符串中的最大相同子串 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);
 }
}

最後更新:2017-04-02 06:51:36

  上一篇:go C++ protected成員訪問權限
  下一篇:go Write to myself