Skip to content

Commit

Permalink
Update basic-calculator-iv.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Jan 22, 2018
1 parent 8f18cdc commit 000fc12
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions C++/basic-calculator-iv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ class Poly {
++polies_[key];
}
}

void update(const vector<string>& key, int val) {
polies_[key] += val;
if (polies_[key] == 0) {
polies_.erase(key);
}
}

operator vector<string>() { // Time: O(d * tlogt)
map<vector<string>, int, Compare<vector<string>>> sorted(polies_.begin(), polies_.end());
vector<string> result;
for (const auto& kvp : sorted) {
vector<string> 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;
Expand Down Expand Up @@ -87,10 +69,28 @@ class Poly {
return result;
}

operator vector<string>() { // Time: O(d * tlogt)
map<vector<string>, int, Compare<vector<string>>> sorted(polies_.begin(), polies_.end());
vector<string> result;
for (const auto& kvp : sorted) {
vector<string> 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<string>& key, int val) {
polies_[key] += val;
if (polies_[key] == 0) {
polies_.erase(key);
}
}

vector<string> merge(const vector<string>& arr1, const vector<string>& arr2) const { // Time: O(d)
vector<string> result;
Expand Down

0 comments on commit 000fc12

Please sign in to comment.