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

#include <leetcode.h>

静态 Public 成员函数

static string decodeString (string s)
 

详细描述

在文件 leetcode.h2966 行定义.

成员函数说明

◆ decodeString()

string leetcode::decode_string::Solution::decodeString ( string  s)
static

在文件 leetcode.cpp8268 行定义.

8268 {
8269 int i = 0;
8270 vector<int> cnt;
8271 vector<string> strs;
8272 while(i < s.length()) {
8273 if(isalpha(s[i]) != 0) {
8274 cnt.emplace_back(1);
8275 strs.emplace_back(string(1, s[i]));
8276 i++;
8277 } else if(isdigit(s[i]) != 0) {
8278 int j = i + 1;
8279 while(j < s.length() && isdigit(s[j]) != 0) {
8280 j++;
8281 }
8282 cnt.emplace_back(stoi(s.substr(i, j - i)));
8283 i = j;
8284 int level = 1;
8285 while(level > 0) {
8286 j++;
8287 if(s[j] == '[') {
8288 level++;
8289 } else if(s[j] == ']') {
8290 level--;
8291 }
8292 }
8293 strs.emplace_back(decodeString(s.substr(i + 1, j - i - 1)));
8294 i = j + 1;
8295 }
8296 }
8297 ostringstream oss;
8298 for(i = 0; i < cnt.size(); i++) {
8299 for(int j = 0; j < cnt[i]; j++) {
8300 oss << strs[i];
8301 }
8302 }
8303 return oss.str();
8304 }
static string decodeString(string s)
Definition: leetcode.cpp:8268

引用了 decodeString().

被这些函数引用 decodeString() , 以及 leetcode::decode_string::TEST().


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