Hacker Rank: Finding Number of Adjacent Characters

 import java.util.ArrayList;

import java.util.Arrays;
import java.util.List;

public class FindingNumberOfAdjancentChracters {

public static List<Integer> findNumberOfAdjacentCharacters(List<String> values){
List<Integer> valuesList =new ArrayList<>();
for(String str:values) {
char[] c= str.toCharArray();

int count=0;

for(int i=0;i<c.length;i++){
if(i>0 && c[i-1]==c[i]){
++count;

i++;
}
}
valuesList.add(count);
}
return valuesList;
}

public static void main(String[] args) {
List<Integer> values =
findNumberOfAdjacentCharacters(Arrays.asList("aabc","bac","bcca"));

System.out.println(values);
}
}

Comments