字符串的旋转

时间限制:3秒 空间限制:32768K 热度指数:25720
本题知识点: 编程基础 字符串

题目描述

对于一个字符串,和字符串中的某一位置,请设计一个算法,将包括i位置在内的左侧部分移动到右边,将右侧部分移动到左边。

给定字符串A和它的长度n以及特定位置p,请返回旋转后的结果。

测试样例:
"ABCDEFGH",8,4
返回:"FGHABCDE"
1 class StringRotation {
2 public:
3     string rotateString(string A, int n, int p) {
4         // write code here
5          return A.substr(p+1)+A.substr(0,p+1);
6     }
7 };
原文地址:https://www.cnblogs.com/bxyan/p/6923659.html