Last active
February 26, 2020 18:20
-
-
Save harbirchahal/476a7312b83ae0522f0e05d823abc5de to your computer and use it in GitHub Desktop.
Mock implementation of String functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class String { | |
public static boolean contains(String s, String t) { | |
for (int i = 0; i < s.length(); i++) { | |
if (s.charAt(i) == t.charAt(0)) { | |
int j = 1; | |
for (; j < t.length(); j++) { | |
if (t.charAt(j) != s.charAt(i + j)) { | |
break; | |
} | |
} | |
if (j == t.length()) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment