Create 2103.cpp

master
Kirigaya Kazuto 2023-11-05 20:17:25 +08:00 committed by GitHub
parent ba0e3702f3
commit 7eaf5a2398
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions

31
LeetCode/2103.cpp Normal file
View File

@ -0,0 +1,31 @@
class Solution {
public:
int countPoints(string rings) {
int rods[10] = {};
for(int i=0; i<rings.size(); i+=2) {
char c = rings[i];
int id = rings[i+1] - '0';
// printf("%c%d\n", c, id);
switch (c) {
case 'R':
rods[id] |= 0x100;
break;
case 'G':
rods[id] |= 0x10;
break;
case 'B':
rods[id] |= 0x1;
break;
}
}
int c = 0;
for(int i=0; i<10; i++) {
// printf("%d %d\n", i, rods[i]);
if (rods[i] == 0x111) c++;
}
return c;
}
};