728x90
반응형
문제 : 해커랭크 - Weighted Uniform Strings
난이도: Easy
언어 : C+
// Complete the weightedUniformStrings function below.
vector<string> weightedUniformStrings(string s, vector<int> queries) {
vector<string> result;
map<int,int> weight;
char prev = 0;
int prevWeight = 0;
for(int i = 0 ;i<s.length();i++)
{
if(prev == s[i])
{
prevWeight+=(s[i]-'a'+1);
}
else
{
prevWeight =(s[i]-'a'+1);
}
weight[prevWeight] = prevWeight;
prev = s[i];
}
for(int i = 0 ;i<queries.size();i++)
{
if( weight.find(queries[i]) != weight.end())
{
result.push_back("Yes");
}else
result.push_back("No");
}
return result;
}
728x90
반응형
'개발 > 코딩' 카테고리의 다른 글
해커랭크(HackerRank) - Left Rotation / C++ (0) | 2020.02.11 |
---|---|
해커랭크(HackerRank) - 2D Array - DS / C++ (0) | 2020.02.11 |
해커랭크(HackerRank) - Day of the Programmer / C++ (0) | 2020.02.05 |
해커랭크(HackerRank) - Migratory Birds / C++ (0) | 2020.02.04 |
해커랭크(HackerRank) - Mini-Max Sum / C++ (0) | 2020.02.04 |
댓글