sweet1cris

Untitled

Sep 7th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1.  
  2. public class Solution {
  3.   public int strstr(String large, String small) {
  4.     // write your solution here
  5.     if (large == null || small == null) {
  6.       return -1;
  7.     }
  8.     for (int i = 0; i < large.length() - small.length() + 1; i++) {
  9.       int cur = i, j = 0;
  10.       for (j = 0; j < small.length(); j++) {
  11.         if (cur < large.length() && large.charAt(cur) != small.charAt(j)) {
  12.           break;
  13.         }
  14.         cur++;
  15.       }
  16.       if (j == small.length()) {
  17.         return i;
  18.       }
  19.     }
  20.     return -1;
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment