leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1807.cpp (620B)
0 class Solution { 1 public: 2 string evaluate(const string &s, const vector<vector<string>> &knowledge) { 3 unordered_map<string, string> um; 4 for (const auto &p : knowledge) 5 um[p[0]] = p[1]; 6 7 string res, key; 8 bool open = false; 9 for (const char c : s) { 10 if (c == '(') 11 open = true; 12 else if (c == ')') { 13 res += um.count(key) ? um[key] : "?"; 14 open = false; 15 key.clear(); 16 } else { 17 (open ? key : res) += c; 18 } 19 } 20 return res; 21 } 22 };