![]() The time complexity of the indexOf(String str) method is O(m*n) where m is the length of the string in which we have to search, and n is the length of the string passed in the arguments. Time complexity of indexOf( String str) method It returned -1 for the string “hello” which was not present in the string. There were two occurrences of the string “codekru” present at the different indices, but indexOf() returned the index of the first occurrence of the string( Remember the indexing is 0-based ). Output – first occurrence of 'codekru' is at index: 3įirst occurrence of 'hello' is at index: -1 ("first occurrence of 'hello' is at index: " + str.indexOf(s2)) ("first occurrence of 'codekru' is at index: " + str.indexOf(s1))
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |