feat: added alternative solution and TLE solution to decode-ways problem, wrote the tutorial file and added some more manual test cases

This commit is contained in:
2025-11-11 11:10:17 -03:00
parent 353fd05093
commit e37b1b1544
200 changed files with 466 additions and 281 deletions

View File

@@ -0,0 +1,45 @@
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll numDecodings(string s)
{
if (s[0] == '0')
return 0;
int N = s.size();
ll dp1 = 1, dp2 = 1;
for (int i = 2; i <= N; i++)
{
ll next = 0;
char current = s[i - 1], last = s[i - 2];
string aux = "";
aux += last;
aux += current;
if (current != '0')
{
next = dp2;
}
int code = stoi(aux);
if (10 <= code && code <= 26)
{
next += dp1;
}
swap(dp1, dp2);
swap(dp2, next);
}
return dp2;
}
int main()
{
int n;
cin >> n;
string code;
cin >> code;
cout << numDecodings(code) << endl;
return 0;
}