mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -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:
|
||||||
```scala
|
```scala
|
||||||
object Solution {
|
object Solution {
|
||||||
|
Reference in New Issue
Block a user