Left rotation string
topic
Left rotational operation in front of the string is the string of several characters to the end of the string transfer.
Define a function to achieve a left rotation operation function string.
For example, the input string "abcdefg" and the number 2, this function returns two results obtained left rotation "cdefgab".
Examples
示例 1:
输入: s = "abcdefg", k = 2
输出: "cdefgab"
示例 2:
输入: s = "lrloseumgh", k = 6
输出: "umghlrlose"
Source: stay button (LeetCode)
link: https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/
copyrighted by deduction from all networks. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source.
Problem-solving ideas
1、
在给定的 `字符串 chars` 中,
截取从 0 到 k (不包含 k) 的一段 `字符串 B` 出来
2、截取从 k(包含 k) 开始到最后的一段 `字符串 A`
3、将 `字符串 A` 与 `字符串 B` 拼接,得到结果
answer
let reverseLeftWords = function(s, k) {
return s.slice(k) + s.slice(0, k)
}
Attach string interception method Essays
String of slice, substring, substr to use