Check if a string is a substring of another | GeeksforGeeks

preview_player
Показать описание
Our courses :

This video is contributed by Anant Patni.

Please Like, Comment and Share the Video among your friends.

Install our Android App:

If you wish, translate into the local language and help us reach millions of other geeks:

Follow us on Facebook:

And Twitter:

Also, Subscribe if you haven't already! :)
#geeksforgeeks
Рекомендации по теме
Комментарии
Автор

worst explanation, this guy just read the code

programmer
Автор

meaningful variable names would go a long way to making this easier to read - especially as this is a fairly introductory tutorial.

MndlssBrndlsm
Автор

function findSubstr() {

let s = 'GeeksforGeeks'
let s2 = "for"
let count = s.match(/for/g)
let res = !count ? false : count.length
if (res >= 1) {
return s.indexOf(s2[0])
}
else {
return -1
}
}

venkat
Автор

Thanks guys keep it up!!🔥🔥 Teaching is one of toughest job. It’s not everyone’s cup of tea!!

alwayswild
Автор

Give two String s1 & s2 find s1 is the substring of s2, if yes remove s1 from s2 and print the remaining String, else return -1.
Input : s1 =the, s2=another
Output : anor
Input : s1=re , s2=apple
Output : -1
Input : s1=ple , s2=appleple
Output : ap

pritamrajput
Автор

I think String matching algorithm like KMP would be better for this purpose.

anukulkumar
Автор

Obviously it's an algorithm for finding if s1 is a substring of s2, and this naive solution is completely useless when M and N become large. Not worth watching.

Unknown-bnyk
Автор

slight typo with the comment before the "isSubstring" method signature. I think you meant "Return true if s1 is substring of s2"

gero
Автор

You are just reading the code !! WTF !!!

abdullahalmahfuj
Автор

doesn't work if string s1 = "geeks" and s2 = "s";

Gokulraj-ldmy
Автор

Inner loop should have the bracket so that break; is also included.

pranavsaihgal