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

[pull] master from youngyangyang04:master #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 6 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jun 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
添加0055.右旋字符串.md PHP版本
  • Loading branch information
KyDestroy committed Jun 6, 2024
commit 3cba050e372565e3d982940c000f33e476e4924c
29 changes: 28 additions & 1 deletion problems/kamacoder/0055.右旋字符串.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
```
2
abcdefg
```
```

样例输出:

Expand Down Expand Up @@ -336,6 +336,32 @@ var reverseLeftWords = function(s, n) {

### PHP:

```php
<?php
// 反转函数
function reverse(&$s, $start, $end) {
for ($i = $start, $j = $end; $i < $j; $i++, $j--) {
$tmp = $s[$i];
$s[$i] = $s[$j];
$s[$j] = $tmp;
}
}

// 标准输入:读取右旋转位数和字符串
$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
// 字符串长度
$len = strlen($s);
// 先部分反转
reverse($s, $len - $n, $len - 1);
reverse($s, 0, $len - $n - 1);
// 再整体反转
reverse($s, 0, $len - 1);

echo $s;
?>
```


### Scala:

Expand All @@ -349,3 +375,4 @@ var reverseLeftWords = function(s, n) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

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