You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2000-2099/2075.Decode the Slanted Ciphertext/README_EN.md
+32-6
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,13 @@ The blue arrows show how we can find originalText from encodedText.
63
63
64
64
## Solutions
65
65
66
-
### Solution 1
66
+
### Solution 1: Simulation
67
+
68
+
First, we calculate the number of columns in the matrix $cols = \text{len}(encodedText) / rows$. Then, following the rules described in the problem, we start traversing the matrix from the top left corner, adding characters to the answer.
69
+
70
+
Finally, we return the answer, making sure to remove any trailing spaces.
71
+
72
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the length of the string $encodedText$.
67
73
68
74
<!-- tabs:start -->
69
75
@@ -104,22 +110,42 @@ public:
104
110
string decodeCiphertext(string encodedText, int rows) {
105
111
string ans;
106
112
int cols = encodedText.size() / rows;
107
-
for (int j = 0; j < cols; ++j)
108
-
for (int x = 0, y = j; x < rows && y < cols; ++x, ++y)
113
+
for (int j = 0; j < cols; ++j) {
114
+
for (int x = 0, y = j; x < rows && y < cols; ++x, ++y) {
0 commit comments