Longest Contiguous Letters | tech::interview
Java Solution:
http://blog.csdn.net/beiyetengqing/article/details/8833908
输出count最多的连续的字符。
For example:
|
|
Java Solution:
http://blog.csdn.net/beiyetengqing/article/details/8833908
public void add(ArrayList<Character> list, int count, int preMaxCount, char current) { if (current == ' ') return; if (count > preMaxCount) { list.clear(); list.add(current); } else if (count == preMaxCount) { list.add(current); } } public ArrayList<Character> getMostFrequentChars(String str) { ArrayList<Character> list = new ArrayList<Character>(); if (str == null || str.length() == 0) return list; char current = str.charAt(0); int count = 1; int preMaxCount = -1; for (int i = 1; i < str.length(); i++) { if (str.charAt(i) == current) { count++; } else { if (count >= preMaxCount) { add(list, count, preMaxCount, current); if (current != ' ') preMaxCount = count; } current = str.charAt(i); count = 1; } } add(list, count, preMaxCount, current); // last case return list; }Read full article from Longest Contiguous Letters | tech::interview