Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 69691f9

Browse files
committed
22w2: add 28 js solution
1 parent d7129b9 commit 69691f9

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@
414414
|31|[Next Permutation](https://leetcode.com/problems/next-permutation/)| |Medium|
415415
|30|[Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words/)| |Hard|
416416
|29|[Divide Two Integers](https://leetcode.com/problems/divide-two-integers/)| |Medium|
417-
|28|[Implement strStr()](https://leetcode.com/problems/implement-strstr/)| |Easy|
417+
|28|[Implement strStr()](https://leetcode.com/problems/implement-strstr/)| [js](./algorithms/implementStrstr/solution.js) |Easy|
418418
|27|[Remove Element](https://leetcode.com/problems/remove-element/)| [js](./algorithms/removeElement/removeElement.js) [python](./algorithms/removeElement/removeElement.python) |Easy|
419419
|26|[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [java](./algorithms/removeDuplicatesFromSortedArray/Solution.java), [js](./algorithms/removeDuplicatesFromSortedArray/Solution.js) |Easy|
420420
|25|[Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/)| |Hard|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// 解法一:用 js 现成的 indexOf api
2+
var strStr = function(haystack, needle) {
3+
if(!needle) return 0;
4+
return haystack.indexOf(needle)
5+
};
6+
7+
8+
// TODO: 解法二:自己实现
9+
// var strStr = function(haystack, needle) {
10+
// // 不存在或者相等时,返回0
11+
// if (!needle || needle === haystack) return 0;
12+
// let h = 0, n = 0, index = 0;
13+
// while (h < haystack.length && haystack.length < needle.length) {
14+
// while (haystack[h] === needle[n] && n < needle.length) {
15+
// if (index === 0) {
16+
// index = h
17+
// }
18+
// n = n + 1;
19+
// }
20+
// if (n === needle.length) {
21+
// return index;
22+
// } else {
23+
// h = h + 1;
24+
// }
25+
// }
26+
// // 找不到或者要查找的字符串大于自己的时候,返回-1
27+
// return -1;
28+
// };

0 commit comments

Comments
 (0)