Skip to content

Commit e33725c

Browse files
authored
Create 2038-remove-colored-pieces-if-both-neighbors-are-the-same-color.js
1 parent 71618eb commit e33725c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {string} colors
3+
* @return {boolean}
4+
*/
5+
const winnerOfGame = function(colors) {
6+
let ac = 0, bc = 0
7+
for(let i = 1, n = colors.length; i < n - 1; i++) {
8+
if(colors[i] === 'A' && colors[i - 1] === 'A' && colors[i + 1] === 'A') ac++
9+
if(colors[i] === 'B' && colors[i - 1] === 'B' && colors[i + 1] === 'B') bc++
10+
}
11+
return ac > bc
12+
};

0 commit comments

Comments
 (0)