Merge pull request #260 from aouos/master

0039.组合总和 JavaScript版本
This commit is contained in:
Carl Sun
2021-05-27 15:31:54 +08:00
committed by GitHub

View File

@ -292,7 +292,32 @@ class Solution:
```
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;
}
}
};
```
-----------------------