601-610¶
611-620¶
621-630¶
631-640¶
641-650¶
651-660¶
661-670¶
671-680¶
681-690¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| class Solution { public: int calPoints(vector <string> &ops) { vector<int> res; for (auto op: ops) { if (op == "C") { res.pop_back(); } else if (op == "D") { res.push_back(res.back() * 2); } else if (op == "+") { res.push_back(res[res.size() - 1] + res[res.size() - 2]); } else { res.push_back(stoi(op)); } } int ans = 0; for (auto it: res) ans += it; return ans; } };
|
691-700¶
相邻两位不同,可以通过二进制11去检测,如果是00或者11则会与运算出00或11,即0或3。
1 2 3 4 5 6 7 8 9 10 11 12
| class Solution { public: bool hasAlternatingBits(int n) { while (n) { if ((n & 3) == 3 || (n & 3) == 0) { return false; } n >>= 1; } return true; } };
|