Skip to content

Commit 488f25d

Browse files
committed
feat: add python and java solutions to leetcode problem: No.0293
1 parent 65dba60 commit 488f25d

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
lines changed

solution/0200-0299/0293.Flip Game/README.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,38 @@
3535
<!-- 这里可写当前语言的特殊实现逻辑 -->
3636

3737
```python
38-
38+
class Solution:
39+
def generatePossibleNextMoves(self, s: str) -> List[str]:
40+
if not s or len(s) < 2:
41+
return []
42+
n = len(s)
43+
res = []
44+
for i in range(n - 1):
45+
if s[i] == '+' and s[i + 1] == '+':
46+
res.append(s[:i] + "--" + s[i + 2:])
47+
return res
3948
```
4049

4150
### **Java**
4251

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

4554
```java
46-
55+
class Solution {
56+
public List<String> generatePossibleNextMoves(String s) {
57+
int n;
58+
if (s == null || (n = s.length()) < 2) return Collections.emptyList();
59+
List<String> res = new ArrayList<>();
60+
for (int i = 0; i < n - 1; ++i) {
61+
if (s.charAt(i) == '+' && s.charAt(i + 1) == '+') {
62+
StringBuilder sb = new StringBuilder(s);
63+
sb.replace(i, i + 2, "--");
64+
res.add(sb.toString());
65+
}
66+
}
67+
return res;
68+
}
69+
}
4770
```
4871

4972
### **...**

solution/0200-0299/0293.Flip Game/README_EN.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,36 @@
2929
### **Python3**
3030

3131
```python
32-
32+
class Solution:
33+
def generatePossibleNextMoves(self, s: str) -> List[str]:
34+
if not s or len(s) < 2:
35+
return []
36+
n = len(s)
37+
res = []
38+
for i in range(n - 1):
39+
if s[i] == '+' and s[i + 1] == '+':
40+
res.append(s[:i] + "--" + s[i + 2:])
41+
return res
3342
```
3443

3544
### **Java**
3645

3746
```java
38-
47+
class Solution {
48+
public List<String> generatePossibleNextMoves(String s) {
49+
int n;
50+
if (s == null || (n = s.length()) < 2) return Collections.emptyList();
51+
List<String> res = new ArrayList<>();
52+
for (int i = 0; i < n - 1; ++i) {
53+
if (s.charAt(i) == '+' && s.charAt(i + 1) == '+') {
54+
StringBuilder sb = new StringBuilder(s);
55+
sb.replace(i, i + 2, "--");
56+
res.add(sb.toString());
57+
}
58+
}
59+
return res;
60+
}
61+
}
3962
```
4063

4164
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public List<String> generatePossibleNextMoves(String s) {
3+
int n;
4+
if (s == null || (n = s.length()) < 2) return Collections.emptyList();
5+
List<String> res = new ArrayList<>();
6+
for (int i = 0; i < n - 1; ++i) {
7+
if (s.charAt(i) == '+' && s.charAt(i + 1) == '+') {
8+
StringBuilder sb = new StringBuilder(s);
9+
sb.replace(i, i + 2, "--");
10+
res.add(sb.toString());
11+
}
12+
}
13+
return res;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def generatePossibleNextMoves(self, s: str) -> List[str]:
3+
if not s or len(s) < 2:
4+
return []
5+
n = len(s)
6+
res = []
7+
for i in range(n - 1):
8+
if s[i] == '+' and s[i + 1] == '+':
9+
res.append(s[:i] + "--" + s[i + 2:])
10+
return res
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
class Solution:
2-
def reverseString(self, s: List[str]) -> None:
3-
"""
4-
Do not return anything, modify s in-place instead.
5-
"""
6-
s[:] = s[::-1]
2+
def generatePossibleNextMoves(self, s: str) -> List[str]:
3+
if not s or len(s) < 2:
4+
return []
5+
n = len(s)
6+
res = []
7+
for i in range(n - 1):
8+
if s[i] == '+' and s[i + 1] == '+':
9+
res.append(s[:i] + "--" + s[i + 2:])
10+
return res

0 commit comments

Comments
 (0)