Skip to content

Commit d17904c

Browse files
committed
feature: decode ways init
1 parent 0adefcb commit d17904c

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include<vector>
4+
#include<string>
5+
using namespace std;
6+
7+
/*
8+
Pattern 1
9+
Linear Recurrence
10+
11+
Description
12+
Let 1 maps to 'A', 2 maps to 'B', ..., 26 to 'Z'.Given a digit sequence, count the number of possible decodings of the given digit sequence.
13+
14+
Consider the input string "123".There are three valid ways to decode it :
15+
"ABC" : The grouping is(1, 2, 3) -> 'A', 'B', 'C'
16+
"AW" : The grouping is(1, 23) -> 'A', 'W'
17+
"LC" : The grouping is(12, 3) -> 'L', 'C'
18+
Note : Groupings that contain invalid codes(e.g., "0" by itself or numbers greater than "26") are not allowed.
19+
For instance, the string "230" is invalid because "0" cannot stand alone, and "30" is greater than "26", so it cannot represent any letter.The task is to find the total number of valid ways to decode a given string.
20+
*/
21+
22+
namespace DecodeWays
23+
{
24+
class DynamicProgramming
25+
{
26+
private:
27+
int CountWaysRecursiveHelper(string& digits, size_t index);
28+
public:
29+
int RecursiveCountWays(string digits);
30+
};
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "../../include/0005_DynamicProgramming/0007_DecodeWays.h"
2+
3+
namespace DecodeWays
4+
{
5+
int DynamicProgramming::CountWaysRecursiveHelper(string& digits, size_t index)
6+
{
7+
size_t digitsLength = digits.size();
8+
9+
if (index >= digitsLength)
10+
{
11+
return 1;
12+
}
13+
}
14+
15+
int DynamicProgramming::RecursiveCountWays(string digits)
16+
{
17+
18+
}
19+
}

source/0005_DynamicProgramming/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(0005DYNAMICPROGRAMMING_SOURCES
66
0004_MinimumCostClimbingStairs.cc
77
0005_HouseRobber1.cc
88
0006_HouseRobber2.cc
9+
0007_DecodeWays.cc
910

1011
)
1112

test/0005_DynamicProgramming/0007_DecodeWaysTest.cc

Whitespace-only changes.

test/0005_DynamicProgramming/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_executable(
2020
0004_MinimumCostClimbingStairsTest.cc
2121
0005_HouseRobber1Test.cc
2222
0006_HouseRobber2Test.cc
23+
0007_DecodeWaysTest.cc
2324

2425
)
2526

0 commit comments

Comments
 (0)