public static boolean search(String a, String b, String c) {
int len = c.length();
boolean found1 = false;
boolean found2 = false;
for (int i = 2; i <= a.length() - len; i++)
if (a.substring(i, i + len).equals(c))
if (a.substring(i - 2, i).equals("aa"))
found1 = true;
for (int i = 2; i <= b.length() - len; i++)
if (b.substring(i, i + len).equals(c))
if (b.substring(i - 2, i).equals("aa"))
found2 = true;
return found1 && found2;
}
Function Call | Return Value | |||
---|---|---|---|---|
search("Hello", "World", "!") | → | |||
search("Computataaional", "Thinkaaing", "i") | → | |||
search("Hello", "World", "o") | → | |||
search("aa...", "Thenaa...", "...") | → | |||
search("Bohemiaan", "Rhaapsody", "a") | → | |||
search("aa!!", "aa!!??", "!!") | → |
Experiment with this code on Gitpod.io