如果字符串中不含有任何 'aaa','bbb' 或 'ccc' 这样的字符串作为子串,那么该字符串就是一个「快乐字符串」。
给你三个整数 a,b ,c,请你返回 任意一个 满足下列全部条件的字符串 s:
s 是一个尽可能长的快乐字符串。
s 中 最多 有a 个字母 'a'、b 个字母 'b'、c 个字母 'c' 。
s 中只含有 'a'、'b' 、'c' 三种字母。
如果不存在这样的字符串 s ,请返回一个空字符串 ""。
```cpp
class Solution {
public:
string longestDiverseString(int a, int b, int c) {
string res;
vector<pair<int, char>> arr = {{a, 'a'}, {b, 'b'}, {c, 'c'}};
while (true) {
sort(arr.begin(), arr.end(), [](const pair<int, char> & p1, const pair<int, char> & p2) {
return p1.first > p2.first;
});
bool hasNext = false;
for (**auto & [freq, ch] : arr**) {
int m = res.size();
if (freq <= 0) {
break;
}
if (m >= 2 && res[m - 2] == ch && res[m - 1] == ch) {
continue;
}
hasNext = true;
res.push_back(ch);
freq--;
break;
}
if (!hasNext) {
break;
}
}
return res;
}
};