File tree 5 files changed +84
-9
lines changed
0300-0399/0344.Reverse String
5 files changed +84
-9
lines changed Original file line number Diff line number Diff line change 35
35
<!-- 这里可写当前语言的特殊实现逻辑 -->
36
36
37
37
``` 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
39
48
```
40
49
41
50
### ** Java**
42
51
43
52
<!-- 这里可写当前语言的特殊实现逻辑 -->
44
53
45
54
``` 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
+ }
47
70
```
48
71
49
72
### ** ...**
Original file line number Diff line number Diff line change 29
29
### ** Python3**
30
30
31
31
``` 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
33
42
```
34
43
35
44
### ** Java**
36
45
37
46
``` 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
+ }
39
62
```
40
63
41
64
### ** ...**
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change 1
1
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
You can’t perform that action at this time.
0 commit comments