Skip to content

Commit 1b75c0c

Browse files
committed
feat: add solutions to lc problem: No.2027
No.2027.Minimum Moves to Convert String
1 parent be02c9c commit 1b75c0c

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

solution/2000-2099/2027.Minimum Moves to Convert String/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,66 @@ func minimumMoves(s string) (ans int) {
129129
}
130130
```
131131

132+
### **TypeScript**
133+
134+
```ts
135+
function minimumMoves(s: string): number {
136+
const n = s.length;
137+
let ans = 0;
138+
let i = 0;
139+
while (i < n) {
140+
if (s[i] === 'X') {
141+
ans++;
142+
i += 3;
143+
} else {
144+
i++;
145+
}
146+
}
147+
return ans;
148+
}
149+
```
150+
151+
### **Rust**
152+
153+
```rust
154+
impl Solution {
155+
pub fn minimum_moves(s: String) -> i32 {
156+
let s = s.as_bytes();
157+
let n = s.len();
158+
let mut ans = 0;
159+
let mut i = 0;
160+
while i < n {
161+
if s[i] == b'X' {
162+
ans += 1;
163+
i += 3;
164+
} else {
165+
i += 1;
166+
}
167+
}
168+
ans
169+
}
170+
}
171+
```
172+
173+
### **C**
174+
175+
```c
176+
int minimumMoves(char *s) {
177+
int n = strlen(s);
178+
int ans = 0;
179+
int i = 0;
180+
while (i < n) {
181+
if (s[i] == 'X') {
182+
ans++;
183+
i += 3;
184+
} else {
185+
i++;
186+
}
187+
}
188+
return ans;
189+
}
190+
```
191+
132192
### **...**
133193
134194
```

solution/2000-2099/2027.Minimum Moves to Convert String/README_EN.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,66 @@ func minimumMoves(s string) (ans int) {
113113
}
114114
```
115115

116+
### **TypeScript**
117+
118+
```ts
119+
function minimumMoves(s: string): number {
120+
const n = s.length;
121+
let ans = 0;
122+
let i = 0;
123+
while (i < n) {
124+
if (s[i] === 'X') {
125+
ans++;
126+
i += 3;
127+
} else {
128+
i++;
129+
}
130+
}
131+
return ans;
132+
}
133+
```
134+
135+
### **Rust**
136+
137+
```rust
138+
impl Solution {
139+
pub fn minimum_moves(s: String) -> i32 {
140+
let s = s.as_bytes();
141+
let n = s.len();
142+
let mut ans = 0;
143+
let mut i = 0;
144+
while i < n {
145+
if s[i] == b'X' {
146+
ans += 1;
147+
i += 3;
148+
} else {
149+
i += 1;
150+
}
151+
}
152+
ans
153+
}
154+
}
155+
```
156+
157+
### **C**
158+
159+
```c
160+
int minimumMoves(char *s) {
161+
int n = strlen(s);
162+
int ans = 0;
163+
int i = 0;
164+
while (i < n) {
165+
if (s[i] == 'X') {
166+
ans++;
167+
i += 3;
168+
} else {
169+
i++;
170+
}
171+
}
172+
return ans;
173+
}
174+
```
175+
116176
### **...**
117177
118178
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int minimumMoves(char *s) {
2+
int n = strlen(s);
3+
int ans = 0;
4+
int i = 0;
5+
while (i < n) {
6+
if (s[i] == 'X') {
7+
ans++;
8+
i += 3;
9+
} else {
10+
i++;
11+
}
12+
}
13+
return ans;
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
impl Solution {
2+
pub fn minimum_moves(s: String) -> i32 {
3+
let s = s.as_bytes();
4+
let n = s.len();
5+
let mut ans = 0;
6+
let mut i = 0;
7+
while i < n {
8+
if s[i] == b'X' {
9+
ans += 1;
10+
i += 3;
11+
} else {
12+
i += 1;
13+
}
14+
}
15+
ans
16+
}
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function minimumMoves(s: string): number {
2+
const n = s.length;
3+
let ans = 0;
4+
let i = 0;
5+
while (i < n) {
6+
if (s[i] === 'X') {
7+
ans++;
8+
i += 3;
9+
} else {
10+
i++;
11+
}
12+
}
13+
return ans;
14+
}

0 commit comments

Comments
 (0)