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

Commit d085229

Browse files
committed
add question 28
1 parent 56c0429 commit d085229

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

1-100/28-implement-strstr.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/**
2-
* @param {string} haystack
3-
* @param {string} needle
4-
* @return {number}
2+
Author :- Rishabh Jain <contact@rishabh1403.com>
3+
Solution for :- https://leetcode.com/problems/implement-strstr/
4+
blog for this code :- https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-implement-strstr
5+
youtube video :- https://youtu.be/pKa_2pLb3Rw
56
*/
7+
68
var strStr = function (haystack, needle) {
79
if (needle.length === 0) {
810
return 0;
@@ -14,7 +16,7 @@ var strStr = function (haystack, needle) {
1416
for (let i = 0; i <= haystackLength - needleLength; i++) {
1517
let flag = true;
1618

17-
for (let j = i, k = 0; j < needleLength + i, k < needleLength; j++ , k++) {
19+
for (let j = i, k = 0; j < needleLength + i, k < needleLength; j++, k++) {
1820
if (haystack[j] !== needle[k]) {
1921
flag = false;
2022
break;
@@ -48,5 +50,6 @@ var strStr = function (haystack, needle) {
4850
};
4951

5052
//////////////////////////////
51-
KMP
52-
Robin karp
53+
// Other Algos that can be used
54+
// KMP
55+
// Robin karp

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Solutions of all the questions from Leetcode in JavaScript.
1616

1717
- 20.Valid Parentheses - [Question](https://leetcode.com/problems/valid-parentheses/) | [Source Code](https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/20-valid-parentheses.js) | [Blog](https://rishabh1403.com/leetcode-solution-of-valid-parentheses-in-javascript)
1818

19+
- 28.Implement strStr() - [Question](https://leetcode.com/problems/implement-strstr/) | [Source Code](https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/28-implement-strstr.js) | [Blog](https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-implement-strstr) | [Youtube Video](https://youtu.be/pKa_2pLb3Rw)
20+
1921
- 35.Search Insert Position - [Question](https://leetcode.com/problems/search-insert-position/) | [Source Code](https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/35-search-insert-position.js) | [Blog](https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-search-insert-position) | [Youtube Video](https://youtu.be/l2XPvyTlC6c)
2022

2123
- 58.Length of Last Word - [Question](https://leetcode.com/problems/length-of-last-word/) | [Source Code](https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/58-length-of-last-word.js) | [Blog](https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-length-of-last-word) | [Youtube Video](https://youtu.be/2PQ4vtnLfnw)

0 commit comments

Comments
 (0)