File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -467,6 +467,42 @@ object Solution {
467
467
def replaceSpace (s : String ): String = {
468
468
s.map(c => if (c == ' ' ) " %20" else c).mkString
469
469
}
470
+ }
471
+ ```
472
+
473
+
474
+ PHP:
475
+ ``` php
476
+ function replaceSpace($s){
477
+ $sLen = strlen($s);
478
+ $moreLen = $this->spaceLen($s) * 2;
479
+
480
+ $head = $sLen - 1;
481
+ $tail = $sLen + $moreLen - 1;
482
+
483
+ $s = $s . str_repeat(' ', $moreLen);
484
+ while ($head != $tail) {
485
+ if ($s[$head] == ' ') {
486
+ $s[$tail--] = '0';
487
+ $s[$tail--] = '2';
488
+ $s[$tail] = '%';
489
+ } else {
490
+ $s[$tail] = $s[$head];
491
+ }
492
+ $head--;
493
+ $tail--;
494
+ }
495
+ return $s;
496
+ }
497
+ // 统计空格个数
498
+ function spaceLen($s){
499
+ $count = 0;
500
+ for ($i = 0; $i < strlen($s); $i++) {
501
+ if ($s[$i] == ' ') {
502
+ $count++;
503
+ }
504
+ }
505
+ return $count;
470
506
}
471
507
```
472
508
You can’t perform that action at this time.
0 commit comments