zoukankan      html  css  js  c++  java
  • 左旋转字符串

    字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。

    示例 1:

    输入: s = "abcdefg", k = 2
    输出: "cdefgab"
    示例 2:

    输入: s = "lrloseumgh", k = 6
    输出: "umghlrlose"

    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

    class Solution {
        public String reverseLeftWords(String s, int n) {
           int len = s.length();
            return s.substring(n,len)+s.substring(0,n);
        }
    }
  • 相关阅读:
    CSU 1122
    CSU 1256
    CSU 1240
    HDU 1874
    CSU 1004
    Problem F CodeForces 16E
    Problem E CodeForces 237C
    Problem C FZU 1901
    12-30
    2016-12-29
  • 原文地址:https://www.cnblogs.com/try-chi/p/12304855.html
Copyright © 2011-2022 走看看