Suppose I have an array list of of values {0,1,1,0,1,1,1} Here the maximum repeat of value 1 in continuous sequence is 3. How do I find the maximum count.
List<String> list = new ArrayList<String>();
for (int i=0;i<5;i++)
{
System.out.println("Enter value");
x = in.nextLine();
list.add(""+x);
}
Map<String, Integer> countMap = new HashMap<>();
for (String word : list) {
Integer count = countMap.get(word);
if(count == null) {
count = 0;
}
countMap.put(word, (count.intValue()+1));
}
This gives total count of same value but I need maximum continuous values.
Aucun commentaire:
Enregistrer un commentaire