lintcode 旋转字符串
2018-01-26 16:32
363 查看
public class Solution {
/*
* @param str: An array of char
* @param offset: An integer
* @return: nothing
*/
public void rotateString(char[] str, int offset) {
if(str.length==0){
return;
}
offset=offset%str.length;
char[] temp=new char[offset];
int j=0;
for(int i=str.length-offset;i<str.length;i++){
temp[j]=str[i];
j++;
}
for(int i=str.length-1;i>=offset;i--){
str[i]=str[i-offset];
}
for(int i=0;i<offset;i++){
str[i]=temp[i];
}
}
}
/*
* @param str: An array of char
* @param offset: An integer
* @return: nothing
*/
public void rotateString(char[] str, int offset) {
if(str.length==0){
return;
}
offset=offset%str.length;
char[] temp=new char[offset];
int j=0;
for(int i=str.length-offset;i<str.length;i++){
temp[j]=str[i];
j++;
}
for(int i=str.length-1;i>=offset;i--){
str[i]=str[i-offset];
}
for(int i=0;i<offset;i++){
str[i]=temp[i];
}
}
}
相关文章推荐
- LintCode 8.旋转字符串 C++
- 【LintCode】Rotate String 旋转字符串
- (lintcode)第8题旋转字符串
- [LintCode]8.旋转字符串
- 【LintCode】旋转字符串 - [Microsoft Onsite III] - Easy
- lintcode:旋转字符串
- lintcode--旋转字符串
- LintCode(easy)旋转字符串(!!!我有史以来解决的问题最快的一次,心酸流泪)
- LintCode【简单】8. 旋转字符串 。代码及思路
- Lintcode 旋转字符串
- 8. 旋转字符串 —— LintCode
- LintCode 面试题 旋转字符串
- LintCode 旋转字符串
- Lintcode 008 :旋转字符串
- LintCode 8.旋转字符串
- 剑指Offer: 翻转单词顺序列、左旋转字符串
- 面试题42:翻转单词顺序VS左旋转字符串
- 【微软100题】定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部。 如把字符串abcdef左旋转2位得到字符串cdefab。请实现字符串左旋转的函数。
- 左旋转字符串
- 算法——从旋转字符串到翻转单词