---
# System prepended metadata

title: \#541 Reverse String II
tags: [leetcode, leetcode-easy, string]

---

# \#541 Reverse String II
## *給定字串s, 正整數k, 回傳一字串s', 使s'的第0~k字元反轉, (k+1)~2k字元保持原樣, (2k+1)~3k反轉...(依此類推)(反轉k的基數倍字串段)*
## Log
 - build 20211014 by syhuang

## 初見
 - 依題意跑迴圈
 - leetcode submit runtime 37%, memory 95%
```javascript=
var reverseStr = function(s, k) {
    let result = '';
    for(let p=0; p*k<s.length; p++){
        if(p%2==0) result+=s.slice(p*k,(p+1)*k).split('').reverse().join('');
        else result+=s.slice(p*k,(p+1)*k)
    }
    return result;
};
```
## 備註
- 初見即畢業
## 參考
###### tags: `leetcode`, `leetcode-easy`, `string`