add: 只出现一次的数字等

This commit is contained in:
2019-03-10 16:43:04 +08:00
committed by yi-ge
parent 930ff1be11
commit 8239e7afd5
106 changed files with 7978 additions and 0 deletions

View File

@ -0,0 +1,7 @@
import { compareStrings } from '../../src/string/compare-strings'
test('比较字符串', () => {
expect(compareStrings('ABCD', 'AB')).toBe(true)
expect(compareStrings('ABCD', 'ACD')).toBe(true)
expect(compareStrings('ABCD', 'AABC')).toBe(false)
})

View File

@ -0,0 +1,7 @@
import { containsDuplicate } from '../../src/string/contains-duplicate'
test('存在重复元素', () => {
expect(containsDuplicate([1, 2, 3, 1])).toBe(true)
expect(containsDuplicate([1, 2, 3, 4])).toBe(false)
expect(containsDuplicate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2])).toBe(true)
})

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,12 @@
import regularExpressionMatching from '../../src/string/regular-expression-matching'
test('regularExpressionMatching', () => {
expect(regularExpressionMatching('aa', 'a')).toEqual(false)
expect(regularExpressionMatching('aaa', 'aa')).toEqual(false)
expect(regularExpressionMatching('aa', 'aa')).toEqual(true)
expect(regularExpressionMatching('aa', 'a*')).toEqual(true)
expect(regularExpressionMatching('ab', '.*')).toEqual(true)
expect(regularExpressionMatching('aab', 'c*a*b')).toEqual(true)
expect(regularExpressionMatching('mississippi', 'mis*is*p*.')).toEqual(false)
expect(regularExpressionMatching('mississippi', 'mis*is*ip*.')).toEqual(true)
})

View File

@ -0,0 +1,8 @@
import repeatedSubstringPattern from '../../src/string/repeated-substring-pattern'
test('repeatedSubstringPattern', () => {
expect(repeatedSubstringPattern('abab')).toEqual(true)
expect(repeatedSubstringPattern('ab')).toEqual(false)
expect(repeatedSubstringPattern('aba')).toEqual(false)
expect(repeatedSubstringPattern('abcabcabcabc')).toEqual(true)
})

View File

@ -0,0 +1,9 @@
import restoreIpAddresses from '../../src/string/restore-ip-addresses'
test('恢复IP地址', () => {
expect(restoreIpAddresses('25525511135')).toEqual(['255.255.11.135', '255.255.111.35'])
expect(restoreIpAddresses('1116512311')).toEqual(['11.165.123.11', '111.65.123.11'])
expect(restoreIpAddresses('00000')).toEqual([])
expect(restoreIpAddresses('0000')).toEqual(['0.0.0.0'])
expect(restoreIpAddresses('010010')).toEqual(['0.10.0.10', '0.100.1.0'])
})

View File

@ -0,0 +1,5 @@
import ReverseWordsInAString from '../../src/string/reverse-words-in-a-string'
test('ReverseWordsInAString', () => {
expect(ReverseWordsInAString('Let\'s take LeetCode contest')).toBe('s\'teL ekat edoCteeL tsetnoc')
})

View File

@ -0,0 +1,6 @@
import { isUnique } from '../../src/string/unique-characters'
test('判断字符串是否没有重复字符', () => {
expect(isUnique('abc___')).toBe(false)
expect(isUnique('abc')).toBe(true)
})