add: 左旋转字符串

This commit is contained in:
yi-ge 2020-05-08 13:12:12 +08:00
parent 3b8d9b3f40
commit c027a13f6e
4 changed files with 26 additions and 1 deletions

View File

@ -1,11 +1,18 @@
{
"cSpell.words": [
"abcdefg",
"cdefgab",
"chuan",
"dvdf",
"lcci",
"lcof",
"lrloseumgh",
"mincost",
"nums",
"pwwkew",
"zhong"
"umghlrlose",
"xuan",
"zhong",
"zhuan"
]
}

View File

@ -67,6 +67,10 @@ LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重
- 面试题参考思路,不严谨实现 廖雪峰 不要使用JavaScript内置的parseInt()函数利用map和reduce操作实现一个string2int()函数。 https://www.liaoxuefeng.com/wiki/1022910821149312/1024322552460832
- [左旋转字符串](src/string/zuo-xuan-zhuan-zi-fu-chuan-lcof.js)
- LeetCode 面试题58 - II. 左旋转字符串 https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/
## 数组
- [电话号码的字母组合](src/array/letter-combinations-of-a-phone-number.js)

View File

@ -0,0 +1,8 @@
/**
* @param {string} s
* @param {number} n
* @return {string}
*/
export const reverseLeftWords = function (s, n) {
return (s + s).substr(n, s.length)
}

View File

@ -0,0 +1,6 @@
import { reverseLeftWords } from '../../src/string/zuo-xuan-zhuan-zi-fu-chuan-lcof'
test('左旋转字符串', () => {
expect(reverseLeftWords('abcdefg', 2)).toBe('cdefgab')
expect(reverseLeftWords('lrloseumgh', 6)).toBe('umghlrlose')
})