[刷题]Rotate String

来源:互联网 发布:vscode html自动补全 编辑:程序博客网 时间:2024/05/21 22:38

[LintCode]Rotate String

public class Solution {    /*     * param A: A string     * param offset: Rotate string with offset.     * return: Rotated string.     */    public char[] rotateString(char[] A, int offset) {        // 2015-4-14 O(n)        if (A == null || A.length == 0) {            return A;        }                int length = A.length;        char[] rst = new char[length];        for (int i = 0; i < length; i++) {            offset %= length;            rst[offset] = A[i];            offset++;        }        return rst;    }};


0 0
原创粉丝点击