mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-12 05:20:59 +08:00
添加(0344.反转字符串.md):PHP版本
This commit is contained in:
@ -267,5 +267,34 @@ 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
-----------------------
|
-----------------------
|
||||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||||
|
Reference in New Issue
Block a user