it's my simple solution for JAVA.


  • 0
    L

    class Solution {
    public int strStr(String h, String n) {
    if(n.isEmpty()){
    return 0;
    }
    for(int i = 0,j=0;i<h.length();){
    if(h.charAt(i) == n.charAt(j)){
    i++;
    j++;
    if(j == n.length()){
    return i - j;
    }
    }else{
    i = i - j + 1;
    j = 0;
    }
    }
    return -1;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.