Files

30 lines
809 B
Java
Raw Permalink Normal View History

2017-04-09 19:12:53 -05:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-04-09 19:12:53 -05:00
import java.util.Scanner;
// Each time we have 2 consecutive characters that are the same, we can delete 1 of them
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while (T-- > 0) {
String str = scan.next();
System.out.println(minimumDeletions(str));
}
scan.close();
}
private static int minimumDeletions(String str) {
int deletions = 0;
for (int i = 1; i < str.length(); i++) {
if (str.charAt(i) == str.charAt(i-1)) {
deletions++;
}
}
return deletions;
}
}