classTimeMap { private: map<string, map<int, string>> store; public: /** Initialize your data structure here. */ TimeMap() { this -> store.clear(); } voidset(string key, string value, int timestamp){ this -> store[key][timestamp] = value; } string get(string key, int timestamp){ auto it = this -> store[key].upper_bound(timestamp); if (it != this -> store[key].begin() && --it != this -> store[key].end()) return it -> second; return""; } };
/** * Your TimeMap object will be instantiated and called as such: * TimeMap* obj = new TimeMap(); * obj->set(key,value,timestamp); * string param_2 = obj->get(key,timestamp); */
classSolution { public: intcountTriplets(vector<int>& a){ int n = a.size(); unordered_map<int, int> m; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) m[a[i] & a[j]]++; int ret = 0; for (int i = 0; i < n; ++i) for (auto mm: m) { if (!(a[i] & (mm.first))) ret += mm.second; } return ret; } };
classSolution { public: string strWithout3a3b(int a, int b){ string sa = "a", sb = "b"; if (b > a) { int t = a; a = b; b = t; sa = "b"; sb = "a"; } string ret = ""; while (a && b && a > b) { ret += sa + sa + sb; a -= 2; b--; } while (a && b) { ret += sa + sb; a--; b--; } while (a--) ret += sa; while (b--) ret += sb; return ret; } };