File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change 1
1
/**
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
5
6
*/
7
+
6
8
var strStr = function ( haystack , needle ) {
7
9
if ( needle . length === 0 ) {
8
10
return 0 ;
@@ -14,7 +16,7 @@ var strStr = function (haystack, needle) {
14
16
for ( let i = 0 ; i <= haystackLength - needleLength ; i ++ ) {
15
17
let flag = true ;
16
18
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 ++ ) {
18
20
if ( haystack [ j ] !== needle [ k ] ) {
19
21
flag = false ;
20
22
break ;
@@ -48,5 +50,6 @@ var strStr = function (haystack, needle) {
48
50
} ;
49
51
50
52
//////////////////////////////
51
- KMP
52
- Robin karp
53
+ // Other Algos that can be used
54
+ // KMP
55
+ // Robin karp
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ Solutions of all the questions from Leetcode in JavaScript.
16
16
17
17
- 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 )
18
18
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
+
19
21
- 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 )
20
22
21
23
- 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 )
You can’t perform that action at this time.
0 commit comments