问题:求两个串的最大子序列(并非连接的)
Java代码:
import java.util.Set; import java.util.StringJoiner; public class Main { public static int getL(String a, String b) { if (a.isEmpty()||b.isEmpty()) return 0; if (a.charAt(0) == b.charAt(0)) return getL(a.substring(1), b.substring(1)) + 1; else return Math.max(getL(a.substring(1), b), getL(a, b.substring(1))); } public static void main(String[] args) { int result = getL("abcfsdgsdgas", "xbaebcdasdasfasfdw"); System.out.println(result); } }
时间: 2024-10-05 10:31:19