File tree 3 files changed +79
-0
lines changed
solution/2000-2099/2000.Reverse Prefix of Word
3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,34 @@ impl Solution {
167
167
}
168
168
```
169
169
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
+
170
198
### ** ...**
171
199
172
200
```
Original file line number Diff line number Diff line change @@ -154,6 +154,34 @@ impl Solution {
154
154
}
155
155
```
156
156
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
+
157
185
### ** ...**
158
186
159
187
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments