LintCode_008_旋转字符串
2017-12-10 19:25
288 查看
问题描述
给定一个字符串和一个偏移量,根据偏移量旋转字符串(从左向右旋转)样例
对于字符串 “abcdefg”.offset=0 => “abcdefg”
offset=1 => “gabcdef”
offset=2 => “fgabcde”
offset=3 => “efgabcd”
求解
翻转前一半,翻转后一半,整体翻转class Solution { public: void rotateString(string &str, int offset) { if (!str.empty()) { offset %= str.length(); reverse(str.begin(), str.begin() + str.length() - offset); reverse(str.begin() + str.length() - offset, str.end()); reverse(str.begin(), str.end()); } } };
相关文章推荐
- LintCode_008_旋转字符串
- lintcode ----旋转字符串
- LintCode之8 旋转字符串
- LintCode容易题练习——8. 旋转字符串
- LintCode-8.旋转字符串
- lintcode :旋转字符串
- LintCode容易题练习——8. 旋转字符串
- LintCode:旋转字符串
- Lintcode:旋转字符串
- LintCode之旋转字符串
- 日常练习:lintcode 8:旋转字符串
- LintCode-8. 旋转字符串
- LintCode 8 旋转字符串
- LintCode C++代码旋转字符串
- Lintcode8——旋转字符串
- lintcode 8.旋转字符串
- lintcode 容易题:Recover Rotated Sorted Array恢复旋转排序数组
- LintCode-[容易] 211. 字符串置换
- 连接两个字符串中的不同字符 lintcode python
- lintcode 中等题:search in rotated sorted arrayII 搜索旋转排序数组II