mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
增加php版本
This commit is contained in:
@ -290,6 +290,25 @@ func reverseString(_ s: inout [Character], startIndex: Int, endIndex: Int) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### PHP
|
||||||
|
|
||||||
|
```php
|
||||||
|
function reverseLeftWords($s, $n) {
|
||||||
|
$this->reverse($s,0,$n-1); //反转区间为前n的子串
|
||||||
|
$this->reverse($s,$n,strlen($s)-1); //反转区间为n到末尾的子串
|
||||||
|
$this->reverse($s,0,strlen($s)-1); //反转整个字符串
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按指定进行翻转 【array、string都可】
|
||||||
|
function reverse(&$s, $start, $end) {
|
||||||
|
for ($i = $start, $j = $end; $i < $j; $i++, $j--) {
|
||||||
|
$tmp = $s[$i];
|
||||||
|
$s[$i] = $s[$j];
|
||||||
|
$s[$j] = $tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user