Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c53082e

Browse files
Merge pull request youngyangyang04#1339 from fmtvar/offer58-2
添加(剑指Offer58-II.左旋转字符串.md):增加PHP版本
2 parents 17a818c + 41eaab2 commit c53082e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎problems/剑指Offer58-II.左旋转字符串.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,28 @@ func reverseString(_ s: inout [Character], startIndex: Int, endIndex: Int) {
290290
}
291291
```
292292

293+
294+
### PHP
295+
296+
```php
297+
function reverseLeftWords($s, $n) {
298+
$this->reverse($s,0,$n-1); //反转区间为前n的子串
299+
$this->reverse($s,$n,strlen($s)-1); //反转区间为n到末尾的子串
300+
$this->reverse($s,0,strlen($s)-1); //反转整个字符串
301+
return $s;
302+
}
303+
304+
// 按指定进行翻转 【array、string都可】
305+
function reverse(&$s, $start, $end) {
306+
for ($i = $start, $j = $end; $i < $j; $i++, $j--) {
307+
$tmp = $s[$i];
308+
$s[$i] = $s[$j];
309+
$s[$j] = $tmp;
310+
}
311+
}
312+
```
313+
314+
293315
Scala:
294316

295317
```scala
@@ -322,5 +344,6 @@ object Solution {
322344

323345

324346

347+
325348
-----------------------
326349
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /