Untitled
unknown
c_cpp
2 years ago
737 B
8
Indexable
class Solution {
public:
int countPoints(string rings) {
short len = rings.length();
short result=0;
short sticks[10] = {0,0,0,0,0,0,0,0,0,0};
short pos = 0;
for (int i = 0; i < len; i += 2){
pos = rings[i+1] - '0';
switch (rings[i]){
case 'R':
sticks[pos] |= 1;
break;
case 'G':
sticks[pos] |= 2;
break;
default:
sticks[pos] |= 4;
break;
}
}
for (int i = 0; i < 10; i++)
if (sticks[i] == 7)
result++;
return result;
}
};Editor is loading...