计算字符串中字符的相连字符的最大长度
2016-12-01 18:34
288 查看
package wusc.edu.test; import java.util.HashMap; public class StringCharCount { public static void main(String args[]){ String str = "AAABBBDDDCCCEFGHJJUAVBBDEBV" ; char[] chars = str.toCharArray() ; HashMap<String,Integer> hm = new HashMap<String,Integer>(); for(int i=0;i<chars.length;i++){ hm.put(String.valueOf(chars[i]), Integer.valueOf(1)); } for(int j=0;j<chars.length;){ if(j==chars.length-1 ||!(chars[j+1]==chars[j])){ j++; continue ; }else{ int k = j ; int count =1 ; while(!(k==chars.length-1)&&(chars[k+1]==chars[k])){ k++; count++; } if(count>hm.get(String.valueOf(chars[j]))){ hm.put(String.valueOf(chars[j]), Integer.valueOf(count)); } j=k; } } System.out.println(hm.toString()); } }
相关文章推荐
- Longest Substring Without Repeating Characters计算字符串中不含有重复字符的连续字符串的最大长度
- 计算两个字符串的最大公共字串的长度,字符不区分大小写(要求计算连续最长字串的长度)
- 题目标题: 计算两个字符串的最大公共字串的长度,字符不区分大小写
- 计算两个字符串的最大公共字符串的长度,字符不区分大小写
- 华为机试:计算两个字符串的最大公共字串的长度,字符不区分大小写
- 一个字符串去除里面的数字,把剩下的字符输出 和 一个字符串计算最大单词的长度并输出这个单词
- 02_对N个长度最长可达到1000的数进行排序、对给定的一个字符串,找出有重复的字符,并给出其位置、输入一系列整数,将其中最大的数挑出,并将剩下的数进行排序
- C++ 计算字符串长度之Function(包含unicode,utf-8),包含特殊字符,欧洲数字千位分隔符,逗号分隔符
- 计算一个字符串中最大的子串的长度,并将它返回。如“abc12345sdfsasdfsd”最大的子串是sdfsasdfsd
- 计算字符串的长度(一个汉字算两个字符)
- 含软连字符的字符串计算显示长度的问题
- (字符串的处理4.7.16)POJ 1159 Palindrome(让一个字符串变成回文串需要插入多少个字符...先逆序,在减去公共子序列的最大长度即可)
- 计算字符串长度,中文俩字符,数字…
- JS计算字符串字符长度
- 2014-03-27工作日志:字符指针指向的字符串的输入、输出、求长度;将字符串与数字相连;
- 计算字符串长度(关于日文字符)
- 计算字符串长度,中文俩字符,数字…
- 一个汉字作为一个字符进行字符串长度计算和切割
- perl中操作mysql,字符匹配与替换,字符串截取,计算字符长度
- 计算未知长度的字符串哪个字符出现的次数最多