Problem Statement
Cat Taro likes strings. You are given a String S. Each character of S is 'A', 'B', or '?'.
To Taro, the ugliness of a string is the number of pairs of equal consecutive characters. For example, the ugliness of "ABABAABBB" is 3: there is one pair "AA" and two (overlapping) pairs "BB".
Taro now wants to change each question mark in S either to 'A' or to 'B'. His goal is to minimize the ugliness of the resulting string. Return the smallest ugliness that can be achieved.
Definition
- Class:
- TaroFillingAStringDiv2
- Method:
- getNumber
- Parameters:
- String
- Returns:
- int
- Method signature:
- int getNumber(String S)
- (be sure your method is public)
Constraints
- S will contain between 1 and 50 characters, inclusive.
- S will consist only of characters 'A', 'B' and '?'.
Examples
"ABAA"
Returns: 1
There is initially one pair of consecutive digits that are equal in this case. There is no characters that Taro has to replace, hence the answer is 1."??"
Returns: 0
"A?A"
Returns: 0
"A??B???AAB?A???A"
Returns: 3
"?BB?BAAB???BAB?B?AAAA?ABBA????A?AAB?BBA?A?"
Returns: 10