mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
feat: add LeetCode problem 2038
This commit is contained in:
parent
e5dad3fa8d
commit
fc57e52031
16
leetcode/src/2038.c
Normal file
16
leetcode/src/2038.c
Normal 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];
|
||||
}
|
Loading…
Reference in New Issue
Block a user