Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public int strstr(String large, String small) {
- // write your solution here
- if (large == null || small == null) {
- return -1;
- }
- for (int i = 0; i < large.length() - small.length() + 1; i++) {
- int cur = i, j = 0;
- for (j = 0; j < small.length(); j++) {
- if (cur < large.length() && large.charAt(cur) != small.charAt(j)) {
- break;
- }
- cur++;
- }
- if (j == small.length()) {
- return i;
- }
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment