3 ms·
for (int i = 0 to text.length() - substring.length()) { boolean found = true; for (int j = 0 to substring.length()) { if (text.charAt(i) !=
by laurent92 5y ago
for (int i = 0 to text.length() - substring.length()) {
boolean found = true;
for (int j = 0 to substring.length()) {
if (text.charAt(i) != substring.charAt(j)) {
found = false; break;
}
if (found) return true;
}
We’re not taking rocket science here. This code already properly handles surrogates and Chinese characters. The question about characters that can be written in two different ways should only be raised as a second level, once the first implementation is done.
- deleted 5y ago[deleted]