일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 109. Convert Sorted List to Binary Search Tree
- DWG
- 운영체제
- iterator
- 30. Substring with Concatenation of All Words
- Python Code
- kaggle
- Convert Sorted List to Binary Search Tree
- Protocol
- 715. Range Module
- 315. Count of Smaller Numbers After Self
- Class
- Regular Expression
- t1
- LeetCode
- Python Implementation
- Python
- shiba
- 밴픽
- 43. Multiply Strings
- attribute
- 컴퓨터의 구조
- 파이썬
- 시바견
- Generator
- 프로그래머스
- Substring with Concatenation of All Words
- data science
- concurrency
- Decorator
Archives
- Today
- Total
Scribbling
[C++] ostringstream, isdigit 본문
LeetCode: 394. Decode String
https://leetcode.com/problems/decode-string/description/
class Solution {
public:
int idx = 0;
string s;
string decodeString(string s) {
this->s = s;
return helper();
}
string helper() {
ostringstream oss;
while (idx < s.size()) {
if (isdigit(s[idx])) {
int num = 0;
while (s[idx] != '[') {
num = num * 10 + s[idx] - '0';
idx++;
}
idx++;
string str = helper();
for (int t = 0; t < num; t++) {
oss << str;
}
}
else if (s[idx] == ']') {
idx++;
return oss.str();
}
else {
oss << s[idx];
idx++;
}
}
return oss.str();
}
};
'Computer Science > C++' 카테고리의 다른 글
[C++] unordered_map, unordered_set, substr (0) | 2023.08.31 |
---|---|
[C++] vector sum, vector max (0) | 2023.08.31 |
[C++] to_string, deque, string split (0) | 2023.08.24 |
[C++] istringstream (0) | 2023.08.22 |
[C++] Chapter 2: Types (0) | 2023.08.21 |