problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::construct_string_with_repeat_limit::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static string repeatLimitedString (const string &s, int repeatLimit)
 

详细描述

在文件 leetcode.h1277 行定义.

成员函数说明

◆ repeatLimitedString()

string leetcode::construct_string_with_repeat_limit::Solution::repeatLimitedString ( const string &  s,
int  repeatLimit 
)
static

在文件 leetcode.cpp3211 行定义.

3211 {
3212 int ch[26] = {};
3213 for(const char c: s) {
3214 ch[c - 'a']++;
3215 }
3216 auto oss = ostringstream();
3217 for(int i = 25; i >= 0; i--) {
3218 int repeat = 0;
3219 while(ch[i] != 0) {
3220 oss << static_cast<char>(i + 'a');
3221 repeat++;
3222 ch[i]--;
3223 if(repeat == repeatLimit && ch[i] != 0) {
3224 for(int j = i - 1; j >= 0; j--) {
3225 if(ch[j] > 0) {
3226 oss << static_cast<char>(j + 'a');
3227 ch[j]--;
3228 repeat = 0;
3229 break;
3230 }
3231 }
3232 if(repeat != 0) {
3233 return oss.str();
3234 }
3235 }
3236 }
3237 }
3238 return oss.str();
3239 }

被这些函数引用 leetcode::construct_string_with_repeat_limit::TEST().


该类的文档由以下文件生成: