Skip to content

Commit e0077ea

Browse files
committed
feat: update solutions to lc problems: No.2325,2327,2328
* No.2325.Decode the Message * No.2327.Number of People Aware of a Secret * No.2328.Number of Increasing Paths in a Grid
1 parent f1b79ce commit e0077ea

File tree

9 files changed

+21
-30
lines changed

9 files changed

+21
-30
lines changed

solution/2300-2399/2325.Decode the Message/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@
7070
```python
7171
class Solution:
7272
def decodeMessage(self, key: str, message: str) -> str:
73-
d = {}
73+
d = {" ": " "}
7474
i = 0
75-
for c in ''.join(key.split()):
75+
for c in key:
7676
if c in d:
7777
continue
7878
d[c] = ascii_lowercase[i]
7979
i += 1
80-
return ''.join([' ' if c == ' ' else d[c] for c in message])
80+
return "".join(d[c] for c in message)
8181
```
8282

8383
### **Java**

solution/2300-2399/2325.Decode the Message/README_EN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ It is obtained by taking the first appearance of each letter in &quot;<u><strong
5858
```python
5959
class Solution:
6060
def decodeMessage(self, key: str, message: str) -> str:
61-
d = {}
61+
d = {" ": " "}
6262
i = 0
63-
for c in ''.join(key.split()):
63+
for c in key:
6464
if c in d:
6565
continue
6666
d[c] = ascii_lowercase[i]
6767
i += 1
68-
return ''.join([' ' if c == ' ' else d[c] for c in message])
68+
return "".join(d[c] for c in message)
6969
```
7070

7171
### **Java**
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class Solution:
22
def decodeMessage(self, key: str, message: str) -> str:
3-
d = {}
3+
d = {" ": " "}
44
i = 0
5-
for c in ''.join(key.split()):
5+
for c in key:
66
if c in d:
77
continue
88
d[c] = ascii_lowercase[i]
99
i += 1
10-
return ''.join([' ' if c == ' ' else d[c] for c in message])
10+
return "".join(d[c] for c in message)

solution/2300-2399/2327.Number of People Aware of a Secret/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@
6464
```python
6565
class Solution:
6666
def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int:
67-
d = [0] * (n + 1010)
68-
cnt = [0] * (n + 1010)
67+
m = (n << 1) + 10
68+
d = [0] * m
69+
cnt = [0] * m
6970
cnt[1] = 1
7071
for i in range(1, n + 1):
7172
if cnt[i]:

solution/2300-2399/2327.Number of People Aware of a Secret/README_EN.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ Day 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6
5454
```python
5555
class Solution:
5656
def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int:
57-
d = [0] * (n + 1010)
58-
cnt = [0] * (n + 1010)
57+
m = (n << 1) + 10
58+
d = [0] * m
59+
cnt = [0] * m
5960
cnt[1] = 1
6061
for i in range(1, n + 1):
6162
if cnt[i]:

solution/2300-2399/2327.Number of People Aware of a Secret/Solution.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
class Solution:
22
def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int:
3-
d = [0] * (n + 1010)
4-
cnt = [0] * (n + 1010)
3+
m = (n << 1) + 10
4+
d = [0] * m
5+
cnt = [0] * m
56
cnt[1] = 1
67
for i in range(1, n + 1):
78
if cnt[i]:

solution/2300-2399/2328.Number of Increasing Paths in a Grid/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ class Solution:
7777

7878
m, n = len(grid), len(grid[0])
7979
mod = 10**9 + 7
80-
ans = 0
81-
for i in range(m):
82-
for j in range(n):
83-
ans += dfs(i, j)
84-
return ans % mod
80+
return sum(dfs(i, j) for i in range(m) for j in range(n)) % mod
8581
```
8682

8783
### **Java**

solution/2300-2399/2328.Number of Increasing Paths in a Grid/README_EN.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ class Solution:
6565

6666
m, n = len(grid), len(grid[0])
6767
mod = 10**9 + 7
68-
ans = 0
69-
for i in range(m):
70-
for j in range(n):
71-
ans += dfs(i, j)
72-
return ans % mod
68+
return sum(dfs(i, j) for i in range(m) for j in range(n)) % mod
7369
```
7470

7571
### **Java**

solution/2300-2399/2328.Number of Increasing Paths in a Grid/Solution.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@ def dfs(i, j):
1111

1212
m, n = len(grid), len(grid[0])
1313
mod = 10**9 + 7
14-
ans = 0
15-
for i in range(m):
16-
for j in range(n):
17-
ans += dfs(i, j)
18-
return ans % mod
14+
return sum(dfs(i, j) for i in range(m) for j in range(n)) % mod

0 commit comments

Comments
 (0)