Skip to content

面试题58 - II. 左旋转字符串

示例

js
示例 1

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

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

JS

解法1:直接使用剪切字符串API

js
/**
 * @param {string} s
 * @param {number} n
 * @return {string}
 */
var reverseLeftWords = function (s, n) {
    return s.slice(n)+s.slice(0,n)
};

题链