feat: add LeetCode problem 2038

This commit is contained in:
gabscrobson 2023-10-03 15:07:18 -03:00
parent e5dad3fa8d
commit fc57e52031

16
leetcode/src/2038.c Normal file
View File

@ -0,0 +1,16 @@
// Remove Colored Pieces if Both Neighbors are the Same Color
// Runtime: O(n)
// Space: O(1)
bool winnerOfGame(char* colors)
{
int points[] = {0, 0};
int len = strlen(colors);
for (int i = 1; i < len; i++)
{
if (colors[i - 1] == colors[i] && colors[i] == colors[i + 1])
points[colors[i] - 'A'] += 1;
}
return points[0] > points[1];
}