funstrCount(str1:String,str2:String):Int{varcount=0varmatchIndex=0vari=0varindexOfFirstMatch=0while(i<str1.length){if(str1[i]==str2[matchIndex]){if(matchIndex==0){indexOfFirstMatch=i}if((++matchIndex)==str2.length){count++matchIndex=0i=indexOfFirstMatch+1}else{i++}}else{i++matchIndex=0}}returncount}funmain(){println(strCount("Hello","o"))println(strCount("Hello","l"))println(strCount("","z"))println(strCount("oh goodness gracious","o"))println(strCount("howdy, pardner","d"))println(strCount("Incumbent President","e"))// also it's fine tooprintln(strCount("Hello helllo","ll"))println(strCount("eeeeeee","ee"))}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Kotlin.