Easy Java Solution


  • 0
    E
    public class Solution {
        public int strStr(String h, String n) {
            int indexH=0;
            while(indexH+n.length()<=h.length()){
                String sub=h.substring(indexH,indexH+n.length());
                if(sub.equals(n)){
                    return indexH;
                }
                indexH++;
            }
            return -1;
        }
    }
    

Log in to reply
 

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