0039.组合总和

This commit is contained in:
aouos
2021-05-26 10:00:14 +08:00
parent 49d45cf949
commit 29ea3ad082

View File

@ -292,7 +292,32 @@ class Solution:
``` ```
Go Go
JavaScript
```js
var strStr = function (haystack, needle) {
if (needle === '') {
return 0;
}
let hayslen = haystack.length;
let needlen = needle.length;
if (haystack === '' || hayslen < needlen) {
return -1;
}
for (let i = 0; i <= hayslen - needlen; i++) {
if (haystack[i] === needle[0]) {
if (haystack.substr(i, needlen) === needle) {
return i;
}
}
if (i === hayslen - needlen) {
return -1;
}
}
};
```
----------------------- -----------------------