classSolution { public: intcountPoints(string s){ unordered_map<int, unordered_set<char>> cnt; int n = s.size(); for (int i = 0; i < n; i += 2) { char col = s[i]; int idx = s[i + 1]; cnt[idx].insert(col); } int ans = 0; for (auto& [k, v] : cnt) if (v.size() == 3) ans += 1; return ans; } };
classSolution { public: intminimumRefill(vector<int>& nums, int a, int b){ int n = nums.size(); int L = 0, R = n - 1; // cA cB 灌水次数 int cA = 0, cB = 0; // curA curB 当前水量 int curA = a, curB = b; while (L <= R) { if (L == R) { // Bob if (curB > curA) { if (curB < nums[L]) cB += 1; } else { // Alice if (curA < nums[L]) cA += 1; } break; } if (curA >= nums[L]) { curA -= nums[L]; } else { curA = a - nums[L]; cA += 1; } if (curB >= nums[R]) { curB -= nums[R]; } else { curB = b - nums[R]; cB += 1; } L += 1, R -= 1; } return cA + cB; } };