Substring algorithm

后端 未结 11 1323
小蘑菇
小蘑菇 2021-02-11 03:38

Can someone explain to me how to solve the substring problem iteratively?

The problem: given two strings S=S1S2S

11条回答
  •  一个人的身影
    2021-02-11 03:49

    Though its pretty old post, I am trying to answer it. Kindly correct me if anything is wrong,

    package com.amaze.substring;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    public class CheckSubstring {
    
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
    
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
        System.out.println("Please enter the main string");
        String mainStr = br.readLine();
    
        System.out.println("Enter the substring that has to be searched");
        String subStr = br.readLine();
    
        char[] mainArr = new char[mainStr.length()];
        mainArr = mainStr.toCharArray();
        char[] subArr = new char[subStr.length()];
        subArr = subStr.toCharArray();
        boolean tracing = false;
        //System.out.println("Length of substring is "+subArr.length);
        int j = 0;
    
        for(int i=0; i

提交回复
热议问题