题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine().toLowerCase();
String newStr = str.replaceAll("([0-9]+)", "*$1");
String newStr1 = newStr.replaceAll("([a-z])", "");
String[] array = newStr1.split("\\*");
int maxLength = 0;
for (String s : array) {
if (s.length() > maxLength) {
maxLength = s.length();
}
}
StringBuilder stringBuilder = new StringBuilder();
for (String s : array) {
if(s.length()==maxLength){
stringBuilder.append(s);
}
}
stringBuilder.append(",");
stringBuilder.append(maxLength);
System.out.println(stringBuilder.toString());
}
}