mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
0039.组合总和
This commit is contained in:
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user