deno.land / x / masx200_leetcode_test@10.6.5 / implement-strstr / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export default function strStr(haystack: string, needle: string): number { if (needle.length == 0) return 0; // return haystack.search(needle)
// const index=haystack.indexOf(needle[0])
// if(index===-1){return -1}
const spl = Array.from(haystack); const ind = [...spl.entries()] .filter(([_i, a]) => a === needle[0]) .map(([i]) => i);
if (ind.length === 0) return -1; for (const i of ind) { if (needle === haystack.slice(i, i + needle.length)) { return i; } } return -1;}
masx200_leetcode_test

Version Info

Tagged at
a year ago