【leetcode】左旋转字符串

 

char* reverseLeftWords(char* s, int n){
    if (n == 0)
        return s;
    int len = strlen(s);
    char* str = (char*)calloc(len+1,sizeof(char));//多一个字节后面放'\0'结束
    n %= len;
    int i = 0;
    for (i = n; i<len+n; i++)
    {
        str[i-n] = s[i%len];
    }    
    return str;
}

 

posted @ 2020-08-20 18:59  温暖了寂寞  阅读(92)  评论(0编辑  收藏  举报