Find the first index of the substring. Condition: Do not use java library function or regular expressions. And measure the performance of your implementation with the standard java library function. Examples: String 1: “abcdefg” String 2: “bcd” Should return 1 String 1: “abcdefg” String 2: “x” Should return -1
Anonymous
static int ReturnFirstOccurance(string mainString, string subString) { int len = mainString.Length; for (int i = 0; i < len; i++) { if (mainString[i] == subString[0]) { if (mainString[i+1] == subString[1]) { if (mainString[i + 1] == subString[1]) { return i; } } } } return -1; }
Check out your Company Bowl for anonymous work chats.