Problem Statement |
| Taro likes colorful things, especially colorful tiles.
Taro's room is divided into L square tiles arranged in a row. Each tile is one of the following four colors: red, green, blue or yellow. You are given a String room. If the i-th character of room is 'R', 'G', 'B' or 'Y', the color of the i-th tile is red, green, blue or yellow, respectively.
He decided to change the color of some tiles so that no two adjacent tiles have the same color. Return the minimal number of tiles he must change. |
|
Definition |
| Class: | ColorfulTilesEasy | Method: | theMin | Parameters: | String | Returns: | int | Method signature: | int theMin(String room) | (be sure your method is public) |
|
|
|
|
Constraints |
- | room will contain between 1 and 10 characters, inclusive. |
- | Each character in room will be 'R', 'G', 'B' or 'Y'. |
|
Examples |
0) | |
| | Returns: 3 | For example, he can change three tiles in the following way:
"RRRRRR" -> "RGRGRG". |
|
|
1) | |
| | Returns: 3 | For example, "GGGGGGG" -> "GRGRGRG". |
|
|
2) | |
| | Returns: 4 | For example, "BBBYYYYYY" -> "BRBYRYRYR". |
|
|
3) | |
| | Returns: 0 | The condition is already satisfied, so he doesn't need to change any tiles. |
|
|
4) | |
| |