(1) 找出两个字符串的最大子串
2016-07-31 14:38
267 查看
package com.legend.debug; /** * Created by Legend on 2016/7/31. */ class StringOperation { private String strA = ""; private String strB = ""; private String[] strarrMax = {"", ""}; public StringOperation(String strA, String strB) { this.strA = strA; this.strB = strB; } public void getMaxSubString() { String strLong = this.strA.length() > this.strB.length() ? this.strA : this.strB; String strShort = this.strA.equals(strLong) ? this.strB : this.strA; int intMaxStringCount = 1; final int FIRST_NUMBER = 0; for (int i = 0; i < strShort.length(); i++) { int intStringNumber = strShort.length() - i; for (int j = strShort.length(); j > strShort.length() - intStringNumber; j--) { if (strLong.contains(strShort.substring(i, j))) { if (strShort.substring(i, j).length() > this.strarrMax[FIRST_NUMBER].length()) { this.strarrMax[FIRST_NUMBER] = strShort.substring(i, j); } else if (strShort.substring(i, j).length() == this.strarrMax[FIRST_NUMBER].length()) { this.strarrMax[intMaxStringCount++] = strShort.substring(i, j); if (intMaxStringCount == strarrMax.length) { System.out.println("the same max substring is too much."); } } } } } } public void print() { for (int k = 0; k < this.strarrMax.length; k++) { System.out.println(this.strarrMax[k]); } } } public class StringDemo { public static void main(String[] args) { /** * sadfcctvghjkl * zxcctvcv 0-7 * 0 length length-1 length-2 length-3 length-4 length-5 length-6 length-7 * 1 length length-1 length-2 length-3 length-4 length-5 length-6 * 2 length length-1 length-2 length-3 length-4 length-5 * 3 length length-1 length-2 length-3 length-4 * 4 length-3 * 5 length-2 * 6 length-1 * 7 length */ String strA = "wsadcctvxghjklseasdpqwert"; String strB = "zxcctvxcvxxsdseasdqwert"; StringOperation stringOperation = new StringOperation(strA, strB); stringOperation.getMaxSubString(); stringOperation.print(); } }
相关文章推荐
- 找出两个字符串中最大子字符串,如"abractyeyt","dgdsaeactyey"的最大子串为"actyet
- 比较两个字符串,找出最大的相同子串
- 找出两个字符串的最大公共子串
- 找出两个字符串中最大公共子字符串,如"abccade","dgcadde"的最大子串为"cad"
- 找出两个字符串中最大公共子字符串,如"abccade","dgcadde"的最大子串为"cad"
- 找出两个字符串中最大公共子字符串,如"abccade","dgcadde"的最大子串为"cad"
- Java找出两个字符串中最大的子串
- 找出两个字符串的最大公共子串
- 找出两个字符串的最大公共子串
- 找出两个字符串中最大的公共子串的简单实现
- java基础—找出两个字符串中最大的子串
- java基础-找出两个字符串相同的最大子串
- 找出两个字符串中最大的公共子串(java实现)
- 135、编程实现:找出两个字符串中最大公共子字符串,如"abccade","dgcadde"的最大子串为 "cad"
- 阿里巴巴2014.08.29校园招聘笔试题---找出两个字符串中连续相同的最大子串
- 找出两个字符串中最大公共子字符串,如"abccade"、"dgcadde"的最大子串为"cad"
- 找出两个字符串中最大公共子字符串,如"abccade","dgcadde"的最大子串为"cad"
- 找出两个字符串中最大的公共子串的简单实现
- 两个或N个字符串最大公共子串算法
- 求两个字符串的公共最大子字符串,如asdfsdkgf,kllsdkabc的最大子串为sdk