This question on LeetCode is a great practice for warm-ups. The approach I used was to count the consecutive occurrences of A and B excluding the ones at the beginning and end of the sequence. However, we can also use the Regular Expression to check who will win the game.
Question
Solution
Regular Expression
For example, the String colors is AAAABBB and Alice got 2 moves and Bob only got 1 move. We can use the replaceAll function to replace consecutive substrings longer than 2 characters with 2 character substrings and compare the length. If the length of replaceStrA(AABBB) is less than the length of replaceStrB(AAAABB), it means that Alice got more moves to do. Theresfore, we can return true if this case happened.