You are viewing a single comment's thread. Return to all comments →
c++ vector weightedUniformStrings(string s, vector queries) { set weight; int count = 1; for (int i = 0; i < s.size(); ++i) { int currentWeight = (s[i] - 'a' + 1); if (i > 0 && s[i] == s[i - 1]) { count++; } else { count = 1; } weight.insert(count * currentWeight); } vector result; for (int q : queries) { if (weight.find(q) != weight.end()) { result.push_back("Yes"); } else { result.push_back("No"); } } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
c++ vector weightedUniformStrings(string s, vector queries) { set weight; int count = 1; for (int i = 0; i < s.size(); ++i) { int currentWeight = (s[i] - 'a' + 1); if (i > 0 && s[i] == s[i - 1]) { count++; } else { count = 1; } weight.insert(count * currentWeight); } vector result; for (int q : queries) { if (weight.find(q) != weight.end()) { result.push_back("Yes"); } else { result.push_back("No"); } } return result; }