lintcode-easy-Rotate String

Posted 哥布林工程师

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lintcode-easy-Rotate String相关的知识,希望对你有一定的参考价值。

Given a string and an offset, rotate string by offset. (rotate from left to right)

Given "abcdefg".

offset=0 => "abcdefg"
offset=1 => "gabcdef"
offset=2 => "fgabcde"
offset=3 => "efgabcd"
public class Solution {
    /**
     * @param str: an array of char
     * @param offset: an integer
     * @return: nothing
     */
    public void rotateString(char[] str, int offset) {
        // write your code here
        if(str == null || str.length == 0)
            return;
        
        int size = str.length;
        
        offset %= size;
        if(offset == 0)
            return;
        
        for(int i = 0; i < offset; i++)
            rotate(str);
        return;
    }
    
    public void rotate(char[] str){
        char temp = str[str.length - 1];
        
        for(int i = str.length - 1; i > 0; i--)
            str[i] = str[i - 1];
        
        str[0] = temp;
        return;
    }
    
}

 

以上是关于lintcode-easy-Rotate String的主要内容,如果未能解决你的问题,请参考以下文章

jboss 错误:java.lang.NoSuchMethodError:org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/Stri

Caused by: javax.el.PropertyNotFoundException: Property [userName] not found on type [java.lang.Stri

mybatis报错: java.lang.IllegalArgumentException invalid comparison: java.util.Date and java.lang.Stri

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/Stri

使用System.IO.Combine(string path1, string path2, string path3)四个参数的重载函数提示`System.IO.Path.Combine(stri

单片机710逆变