public static boolean search(String a, String b, String c) {
int len = c.length();
for (int i = 0; i <= a.length() - len; i++)
if (a.substring(i, i + len).equals(c))
return true;
for (int i = 0; i <= b.length() - len; i++)
if (b.substring(i, i + len).equals(c))
return true;
return false;
}
Function Call | Return Value | |||
---|---|---|---|---|
search("Hello", "World", "!") | → | |||
search("Hello", "World", "e") | → | |||
search("Bohemian", "Rhapsody", "pa") | → | |||
search("!!", "??", "aaaa") | → | |||
search("Computational", "Thinking", "Hi") | → | |||
search("Ok", "Then...", "...") | → |
Experiment with this code on Gitpod.io