我的代码: String.prototype.delete = function (N) {
var thatStr = this
var max = thatStr.length
if (N > max)
return 0
else if (N <= 0 || N == max)
return 1
else {
var hash = {}
for (var i = 0; i + N <= max; i++) {
var sub = thatStr.slice(0, i)
sub += thatStr.slice(i + N)
if (!(sub in hash))
hash[sub] = 1
}
return Object.keys(hash).length
}
}
var str = 'sogou'
console.log(str.delete(0)) // 1
console.log(str.delete(1)) // 5
console.log(str.delete(2)) // 3