-
Notifications
You must be signed in to change notification settings - Fork 693
/
Solution.java
40 lines (35 loc) · 1.05 KB
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Problem: https://www.hackerrank.com/challenges/alternating-characters
//Java 8
/*
Initial thoughts:
Remove all duplicates and problem is solved
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner input = new Scanner(System.in);
int T = input.nextInt();
input.nextLine();
tests:
for(int t = 0; t < T; t++)
{
String s = input.nextLine();
int deletions = 0;
int currentCount = 1;
for(int i = 1; i < s.length(); i++)
{
if(s.charAt(i) != s.charAt(i-1))
{
deletions += currentCount - 1;
currentCount = 1;
continue;
}
currentCount++;
}
deletions += currentCount - 1;
System.out.println(deletions);
}
}
}