diff --git a/C++/basic-calculator-iv.cpp b/C++/basic-calculator-iv.cpp index 3efb56c63..758f40857 100644 --- a/C++/basic-calculator-iv.cpp +++ b/C++/basic-calculator-iv.cpp @@ -18,24 +18,6 @@ class Poly { ++polies_[key]; } } - - void update(const vector& key, int val) { - polies_[key] += val; - if (polies_[key] == 0) { - polies_.erase(key); - } - } - - operator vector() { // Time: O(d * tlogt) - map, int, Compare>> sorted(polies_.begin(), polies_.end()); - vector result; - for (const auto& kvp : sorted) { - vector tmp(kvp.first); - tmp.emplace(tmp.begin(), to_string(kvp.second)); - result.emplace_back(join(tmp, "*")); - } - return result; - } Poly operator+(const Poly &rhs) const { // Time: O(d * t) Poly result; @@ -87,10 +69,28 @@ class Poly { return result; } + operator vector() { // Time: O(d * tlogt) + map, int, Compare>> sorted(polies_.begin(), polies_.end()); + vector result; + for (const auto& kvp : sorted) { + vector tmp(kvp.first); + tmp.emplace(tmp.begin(), to_string(kvp.second)); + result.emplace_back(join(tmp, "*")); + } + return result; + } + private: bool is_number(const std::string &s) { return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit); } + + void update(const vector& key, int val) { + polies_[key] += val; + if (polies_[key] == 0) { + polies_.erase(key); + } + } vector merge(const vector& arr1, const vector& arr2) const { // Time: O(d) vector result;