标签:com array code int www ram public char 接受
class Solution {
public:
/**
* @param str: An array of char
* @param offset: An integer
* @return: nothing
*/
void rotateString(string &str, int offset) {
string t_str;
int len = str.length();
if (len == 0 || offset == 0)return;
int new_offset = offset % len;
int j = len - 1;
for (int i = 0; i< new_offset; i++)
{
t_str.insert(0,1 ,str[j]);
j--;
}
if (new_offset == 0)new_offset = len;
for (int i=0;i!=j+1;i++)
{
t_str.push_back(str[i]);
}
for (int i = 0; i < len; i++)
{
str[i] = t_str[i];
}
}
};
没能想出O(1)的题解
所以就直接暴力解了,复杂度勉强能接受
标签:com array code int www ram public char 接受
原文地址:https://www.cnblogs.com/virgildevil/p/11781414.html