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
commit c08f7b383d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

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;
}
}
};
```
-----------------------