1 Random Problem
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
@@ -0,0 +1,24 @@
class Solution {
public:
int magicalString(const int n) const {
if (n <= 3) return 1;
queue<int> q;
q.push(2);
int count = 2, res = 1, last = 2;
while (!q.empty()) {
const int crnt = q.front();
q.pop();
res += crnt == 1;
if (++count == n) return res;
last = last == 1 ? 2 : 1;
for (int i = 0; i < crnt; i++)
q.push(last);
}
return -1;
}
};
@@ -351,6 +351,7 @@
for solving problems.
| 0463 | Easy | [Island Perimeter](Problems/0463.cpp) |
| 0472 | Hard | [Concatenated Words](Problems/0472.cpp) |
| 0477 | Medium | [Total Hamming Distance](Problems/0477.cpp) |
| 0481 | Medium | [Magical String](Problems/0481.cpp) |
| 0485 | Easy | [Max Consecutive Ones](Problems/0485.cpp) |
| 0486 | Medium | [Reachable Nodes With Restrictions](Problems/0486.cpp) |
| 0491 | Medium | [Non-decreasing Subsequences](Problems/0491.cpp) |