package i.tommy.test.Test;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class matchers
{
static String words = "ggggiuiiipppppaaaaahhhhddddd";
public static void main(String[] args)
{
System.out.println(getLongs());
}
/*
* 返回连续单个字符出现最多次数的字符和个数
*/
public static String getLongs()
{
Pattern pattern = Pattern.compile("([a-zA-Z])\\1+");
Matcher matcher = pattern.matcher(words);
String word = "";
while (matcher.find())
{
String index = matcher.group();
if (word.length() < index.length())
{
word = index;
}
}
return word.substring(0, 1) + "," + word.length();
}
}
一个面试题寻找字符串连续重复次数最多的字符和个数
最新推荐文章于 2024-07-25 18:43:45 发布