leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 9626ead947fb0659888ed06de10b4cc83e9689d7 |
parent | 558b26de15c97da88cb6cce6f430348e1100ad84 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Fri, 17 Mar 2023 15:16:05 +0100 |
Random Problem
Diffstat:A | Problems/0038.cpp | | | +++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/Problems/0038.cpp b/Problems/0038.cpp
@@ -0,0 +1,21 @@
class Solution {
public:
string countAndSay(int n) {
string crnt = "1";
for (int i = 1; i < n; i++) {
string res = "";
int c = crnt.front(), count = 1;
for (int i = 1; i < crnt.size(); i++) {
if (crnt[i] == c)
count++;
else {
res += to_string(count) + (char)c;
count = 1;
c = crnt[i];
}
}
crnt = res + to_string(count) + (char)c;
}
return crnt;
}
};
diff --git a/README.md b/README.md
@@ -55,6 +55,7 @@ for solving problems.
| 0035 | Easy | [Search Insert Position](Problems/0035.cpp) |
| 0036 | Medium | [Valid Sudoku](Problems/0036.cpp) |
| 0037 | Hard | [Sudoku Solver](Problems/0037.cpp) |
| 0038 | Medium | [Count and Say](Problems/0038.cpp) |
| 0039 | Medium | [Combination Sum](Problems/0039.cpp) |
| 0040 | Medium | [Combination Sum II](Problems/0040.cpp) |
| 0042 | Medium | [Trapping Rain Water](Problems/0011.cpp) |