Skip to content

Commit 3683e10

Browse files
committed
feat: update solutions to lc problems: No.2151,2194
* No.2151.Maximum Good People Based on Statements * No.2194.Cells in a Range on an Excel Sheet
1 parent 09a11fa commit 3683e10

File tree

10 files changed

+130
-22
lines changed

10 files changed

+130
-22
lines changed

solution/2100-2199/2151.Maximum Good People Based on Statements/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ class Solution:
101101
def maximumGood(self, statements: List[List[int]]) -> int:
102102
def check(k):
103103
cnt = 0
104-
for i in range(n):
104+
for i, s in enumerate(statements):
105105
if (k >> i) & 1:
106106
for j in range(n):
107-
if statements[i][j] < 2 and ((k >> j) & 1) != statements[i][j]:
107+
if s[j] < 2 and ((k >> j) & 1) != s[j]:
108108
return 0
109109
cnt += 1
110110
return cnt
@@ -195,10 +195,10 @@ func maximumGood(statements [][]int) int {
195195
n := len(statements)
196196
check := func(k int) int {
197197
cnt := 0
198-
for i := 0; i < n; i++ {
198+
for i, s := range statements {
199199
if ((k >> i) & 1) == 1 {
200200
for j := 0; j < n; j++ {
201-
if statements[i][j] < 2 && ((k>>j)&1) != statements[i][j] {
201+
if s[j] < 2 && ((k>>j)&1) != s[j] {
202202
return 0
203203
}
204204
}
@@ -224,8 +224,6 @@ func max(a, b int) int {
224224

225225
### **TypeScript**
226226

227-
<!-- 这里可写当前语言的特殊实现逻辑 -->
228-
229227
```ts
230228

231229
```

solution/2100-2199/2151.Maximum Good People Based on Statements/README_EN.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ class Solution:
9595
def maximumGood(self, statements: List[List[int]]) -> int:
9696
def check(k):
9797
cnt = 0
98-
for i in range(n):
98+
for i, s in enumerate(statements):
9999
if (k >> i) & 1:
100100
for j in range(n):
101-
if statements[i][j] < 2 and ((k >> j) & 1) != statements[i][j]:
101+
if s[j] < 2 and ((k >> j) & 1) != s[j]:
102102
return 0
103103
cnt += 1
104104
return cnt
@@ -111,7 +111,6 @@ class Solution:
111111

112112
```java
113113
class Solution {
114-
115114
private int n;
116115
private int[][] statements;
117116

@@ -130,10 +129,7 @@ class Solution {
130129
for (int i = 0; i < n; ++i) {
131130
if (((k >> i) & 1) == 1) {
132131
for (int j = 0; j < n; ++j) {
133-
if (
134-
statements[i][j] < 2 &&
135-
((k >> j) & 1) != statements[i][j]
136-
) {
132+
if (statements[i][j] < 2 && ((k >> j) & 1) != statements[i][j]) {
137133
return 0;
138134
}
139135
}
@@ -143,7 +139,6 @@ class Solution {
143139
return cnt;
144140
}
145141
}
146-
147142
```
148143

149144
### **C++**
@@ -187,10 +182,10 @@ func maximumGood(statements [][]int) int {
187182
n := len(statements)
188183
check := func(k int) int {
189184
cnt := 0
190-
for i := 0; i < n; i++ {
185+
for i, s := range statements {
191186
if ((k >> i) & 1) == 1 {
192187
for j := 0; j < n; j++ {
193-
if statements[i][j] < 2 && ((k>>j)&1) != statements[i][j] {
188+
if s[j] < 2 && ((k>>j)&1) != s[j] {
194189
return 0
195190
}
196191
}

solution/2100-2199/2151.Maximum Good People Based on Statements/Solution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ func maximumGood(statements [][]int) int {
22
n := len(statements)
33
check := func(k int) int {
44
cnt := 0
5-
for i := 0; i < n; i++ {
5+
for i, s := range statements {
66
if ((k >> i) & 1) == 1 {
77
for j := 0; j < n; j++ {
8-
if statements[i][j] < 2 && ((k>>j)&1) != statements[i][j] {
8+
if s[j] < 2 && ((k>>j)&1) != s[j] {
99
return 0
1010
}
1111
}

solution/2100-2199/2151.Maximum Good People Based on Statements/Solution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ class Solution:
22
def maximumGood(self, statements: List[List[int]]) -> int:
33
def check(k):
44
cnt = 0
5-
for i in range(n):
5+
for i, s in enumerate(statements):
66
if (k >> i) & 1:
77
for j in range(n):
8-
if statements[i][j] < 2 and ((k >> j) & 1) != statements[i][j]:
8+
if s[j] < 2 and ((k >> j) & 1) != s[j]:
99
return 0
1010
cnt += 1
1111
return cnt

solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,56 @@
7070
<!-- 这里可写当前语言的特殊实现逻辑 -->
7171

7272
```python
73-
73+
class Solution:
74+
def cellsInRange(self, s: str) -> List[str]:
75+
return [chr(i) + str(j) for i in range(ord(s[0]), ord(s[-2]) + 1) for j in range(int(s[1]), int(s[-1]) + 1)]
7476
```
7577

7678
### **Java**
7779

7880
<!-- 这里可写当前语言的特殊实现逻辑 -->
7981

8082
```java
83+
class Solution {
84+
public List<String> cellsInRange(String s) {
85+
List<String> ans = new ArrayList<>();
86+
for (char i = s.charAt(0); i <= s.charAt(3); ++i) {
87+
for (char j = s.charAt(1); j <= s.charAt(4); ++j) {
88+
ans.add(i + "" + j);
89+
}
90+
}
91+
return ans;
92+
}
93+
}
94+
```
95+
96+
### **C++**
97+
98+
```cpp
99+
class Solution {
100+
public:
101+
vector<string> cellsInRange(string s) {
102+
vector<string> ans;
103+
for (char i = s[0]; i <= s[3]; ++i)
104+
for (char j = s[1]; j <= s[4]; ++j)
105+
ans.push_back({i, j});
106+
return ans;
107+
}
108+
};
109+
```
81110
111+
### **Go**
112+
113+
```go
114+
func cellsInRange(s string) []string {
115+
var ans []string
116+
for i := s[0]; i <= s[3]; i++ {
117+
for j := s[1]; j <= s[4]; j++ {
118+
ans = append(ans, string(i)+string(j))
119+
}
120+
}
121+
return ans
122+
}
82123
```
83124

84125
### **TypeScript**

solution/2100-2199/2194.Cells in a Range on an Excel Sheet/README_EN.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,54 @@ The red arrow denotes the order in which the cells should be presented.
5858
### **Python3**
5959

6060
```python
61-
61+
class Solution:
62+
def cellsInRange(self, s: str) -> List[str]:
63+
return [chr(i) + str(j) for i in range(ord(s[0]), ord(s[-2]) + 1) for j in range(int(s[1]), int(s[-1]) + 1)]
6264
```
6365

6466
### **Java**
6567

6668
```java
69+
class Solution {
70+
public List<String> cellsInRange(String s) {
71+
List<String> ans = new ArrayList<>();
72+
for (char i = s.charAt(0); i <= s.charAt(3); ++i) {
73+
for (char j = s.charAt(1); j <= s.charAt(4); ++j) {
74+
ans.add(i + "" + j);
75+
}
76+
}
77+
return ans;
78+
}
79+
}
80+
```
81+
82+
### **C++**
83+
84+
```cpp
85+
class Solution {
86+
public:
87+
vector<string> cellsInRange(string s) {
88+
vector<string> ans;
89+
for (char i = s[0]; i <= s[3]; ++i)
90+
for (char j = s[1]; j <= s[4]; ++j)
91+
ans.push_back({i, j});
92+
return ans;
93+
}
94+
};
95+
```
6796
97+
### **Go**
98+
99+
```go
100+
func cellsInRange(s string) []string {
101+
var ans []string
102+
for i := s[0]; i <= s[3]; i++ {
103+
for j := s[1]; j <= s[4]; j++ {
104+
ans = append(ans, string(i)+string(j))
105+
}
106+
}
107+
return ans
108+
}
68109
```
69110

70111
### **TypeScript**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
vector<string> cellsInRange(string s) {
4+
vector<string> ans;
5+
for (char i = s[0]; i <= s[3]; ++i)
6+
for (char j = s[1]; j <= s[4]; ++j)
7+
ans.push_back({i, j});
8+
return ans;
9+
}
10+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
func cellsInRange(s string) []string {
2+
var ans []string
3+
for i := s[0]; i <= s[3]; i++ {
4+
for j := s[1]; j <= s[4]; j++ {
5+
ans = append(ans, string(i)+string(j))
6+
}
7+
}
8+
return ans
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public List<String> cellsInRange(String s) {
3+
List<String> ans = new ArrayList<>();
4+
for (char i = s.charAt(0); i <= s.charAt(3); ++i) {
5+
for (char j = s.charAt(1); j <= s.charAt(4); ++j) {
6+
ans.add(i + "" + j);
7+
}
8+
}
9+
return ans;
10+
}
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def cellsInRange(self, s: str) -> List[str]:
3+
return [chr(i) + str(j) for i in range(ord(s[0]), ord(s[-2]) + 1) for j in range(int(s[1]), int(s[-1]) + 1)]

0 commit comments

Comments
 (0)