0039.组合总和
This commit is contained in:
parent
49d45cf949
commit
29ea3ad082
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue