add: 最长公共前缀

This commit is contained in:
2020-05-24 19:42:58 +08:00
parent 581a96e795
commit 8ca4a189f8
4 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,8 @@
import { longestCommonPrefix } from '../../src/string/longest-common-prefix'
test('最长公共前缀', () => {
expect(longestCommonPrefix(['flower', 'flow', 'flight'])).toBe('fl')
expect(longestCommonPrefix(['dog', 'racecar', 'car'])).toBe('')
expect(longestCommonPrefix(['a'])).toBe('a')
expect(longestCommonPrefix(['caa', '', 'a', 'acb'])).toBe('')
})