Skip to content

Commit b9302bc

Browse files
authoredMar 20, 2023
feat: add php solution to lc problem: No.2000 (doocs#941)
No.2000.Reverse Prefix of Word
1 parent 9952724 commit b9302bc

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
 

‎solution/2000-2099/2000.Reverse Prefix of Word/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ impl Solution {
167167
}
168168
```
169169

170+
### **PHP**
171+
172+
```php
173+
class Solution {
174+
/**
175+
* @param String $word
176+
* @param String $ch
177+
* @return String
178+
*/
179+
function reversePrefix($word, $ch) {
180+
$len = strlen($word);
181+
$rs = '';
182+
for ($i = 0; $i < $len; $i++) {
183+
$rs = $rs.$word[$i];
184+
if ($word[$i] == $ch) {
185+
break;
186+
}
187+
}
188+
if (strlen($rs) == $len && $rs[$len - 1] != $ch) {
189+
return $word;
190+
}
191+
$rs = strrev($rs);
192+
$rs = $rs.substr($word, strlen($rs));
193+
return $rs;
194+
}
195+
}
196+
```
197+
170198
### **...**
171199

172200
```

‎solution/2000-2099/2000.Reverse Prefix of Word/README_EN.md

+28
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,34 @@ impl Solution {
154154
}
155155
```
156156

157+
### **PHP**
158+
159+
```php
160+
class Solution {
161+
/**
162+
* @param String $word
163+
* @param String $ch
164+
* @return String
165+
*/
166+
function reversePrefix($word, $ch) {
167+
$len = strlen($word);
168+
$rs = '';
169+
for ($i = 0; $i < $len; $i++) {
170+
$rs = $rs.$word[$i];
171+
if ($word[$i] == $ch) {
172+
break;
173+
}
174+
}
175+
if (strlen($rs) == $len && $rs[$len - 1] != $ch) {
176+
return $word;
177+
}
178+
$rs = strrev($rs);
179+
$rs = $rs.substr($word, strlen($rs));
180+
return $rs;
181+
}
182+
}
183+
```
184+
157185
### **...**
158186

159187
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
/**
3+
* @param String $word
4+
* @param String $ch
5+
* @return String
6+
*/
7+
function reversePrefix($word, $ch) {
8+
$len = strlen($word);
9+
$rs = '';
10+
for ($i = 0; $i < $len; $i++) {
11+
$rs = $rs.$word[$i];
12+
if ($word[$i] == $ch) {
13+
break;
14+
}
15+
}
16+
if (strlen($rs) == $len && $rs[$len - 1] != $ch) {
17+
return $word;
18+
}
19+
$rs = strrev($rs);
20+
$rs = $rs.substr($word, strlen($rs));
21+
return $rs;
22+
}
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.