AcWing 2558. 最长子序列
原题链接
简单
作者:
轻萝
,
2021-06-03 10:45:08
,
所有人可见
,
阅读 275
StringBuilder+char[]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
StringBuilder sb=new StringBuilder();
sb.append(sc.nextLine());
String str=sc.nextLine();
char[] ch=str.toCharArray();
for(int i=0;i<str.length();i++)
{
int index=sb.indexOf(String.valueOf(ch[i]));
if(index!=-1)
{
sb.delete(0,index+1);
System.out.println(sb);
}
else
{
System.out.println(i);
break;
}
}
}
}