diff --git a/problems/0344.反转字符串.md b/problems/0344.反转字符串.md index e1f27bd7..3198f856 100644 --- a/problems/0344.反转字符串.md +++ b/problems/0344.反转字符串.md @@ -266,6 +266,38 @@ public class Solution } } ``` + + +PHP: +```php +// 双指针 +// 一: +function reverseString(&$s) { + $left = 0; + $right = count($s)-1; + while($left<$right){ + $temp = $s[$left]; + $s[$left] = $s[$right]; + $s[$right] = $temp; + $left++; + $right--; + } +} + +// 二: +function reverseString(&$s) { + $this->reverse($s,0,count($s)-1); +} +// 按指定位置交换元素 +function reverse(&$s, $start, $end) { + for ($i = $start, $j = $end; $i < $j; $i++, $j--) { + $tmp = $s[$i]; + $s[$i] = $s[$j]; + $s[$j] = $tmp; + } + } +``` + Scala: ```scala object Solution {