add: 左旋转字符串
This commit is contained in:
		
							
								
								
									
										9
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							@ -1,11 +1,18 @@
 | 
			
		||||
{
 | 
			
		||||
  "cSpell.words": [
 | 
			
		||||
    "abcdefg",
 | 
			
		||||
    "cdefgab",
 | 
			
		||||
    "chuan",
 | 
			
		||||
    "dvdf",
 | 
			
		||||
    "lcci",
 | 
			
		||||
    "lcof",
 | 
			
		||||
    "lrloseumgh",
 | 
			
		||||
    "mincost",
 | 
			
		||||
    "nums",
 | 
			
		||||
    "pwwkew",
 | 
			
		||||
    "zhong"
 | 
			
		||||
    "umghlrlose",
 | 
			
		||||
    "xuan",
 | 
			
		||||
    "zhong",
 | 
			
		||||
    "zhuan"
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								src/string/zuo-xuan-zhuan-zi-fu-chuan-lcof.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/string/zuo-xuan-zhuan-zi-fu-chuan-lcof.js
									
									
									
									
									
										Normal 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)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								test/string/zuo-xuan-zhuan-zi-fu-chuan-lcof.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								test/string/zuo-xuan-zhuan-zi-fu-chuan-lcof.test.js
									
									
									
									
									
										Normal 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')
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user