File tree 3 files changed +40
-0
lines changed
solution/2000-2099/2075.Decode the Slanted Ciphertext
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,21 @@ class Solution {
120
120
}
121
121
```
122
122
123
+ ### ** TypeScript**
124
+
125
+ ``` ts
126
+ function decodeCiphertext(encodedText : string , rows : number ): string {
127
+ const cols = Math .ceil (encodedText .length / rows );
128
+ let ans = [];
129
+ for (let k = 0 ; k <= cols ; k ++ ) {
130
+ for (let i = 0 , j = k ; i < rows && j < cols ; i ++ , j ++ ) {
131
+ ans .push (encodedText .charAt (i * cols + j ));
132
+ }
133
+ }
134
+ return ans .join (' ' ).trimEnd ();
135
+ };
136
+ ```
137
+
123
138
### ** C++**
124
139
125
140
``` cpp
Original file line number Diff line number Diff line change @@ -106,6 +106,21 @@ class Solution {
106
106
}
107
107
```
108
108
109
+ ### ** TypeScript**
110
+
111
+ ``` ts
112
+ function decodeCiphertext(encodedText : string , rows : number ): string {
113
+ const cols = Math .ceil (encodedText .length / rows );
114
+ let ans = [];
115
+ for (let k = 0 ; k <= cols ; k ++ ) {
116
+ for (let i = 0 , j = k ; i < rows && j < cols ; i ++ , j ++ ) {
117
+ ans .push (encodedText .charAt (i * cols + j ));
118
+ }
119
+ }
120
+ return ans .join (' ' ).trimEnd ();
121
+ };
122
+ ```
123
+
109
124
### ** C++**
110
125
111
126
``` cpp
Original file line number Diff line number Diff line change
1
+ function decodeCiphertext ( encodedText : string , rows : number ) : string {
2
+ const cols = Math . ceil ( encodedText . length / rows ) ;
3
+ let ans = [ ] ;
4
+ for ( let k = 0 ; k <= cols ; k ++ ) {
5
+ for ( let i = 0 , j = k ; i < rows && j < cols ; i ++ , j ++ ) {
6
+ ans . push ( encodedText . charAt ( i * cols + j ) ) ;
7
+ }
8
+ }
9
+ return ans . join ( '' ) . trimEnd ( ) ;
10
+ } ;
You can’t perform that action at this time.
0 commit comments