()
| 38 | |
| 39 | |
| 40 | private void createLPS() { |
| 41 | int i=0,j=1; |
| 42 | this.lps[0] = 0; |
| 43 | |
| 44 | while(j<this.pattern.length()) { |
| 45 | if(this.pattern.charAt(i) == this.pattern.charAt(j)) { |
| 46 | this.lps[j] = i+1; |
| 47 | i++; |
| 48 | j++; |
| 49 | } |
| 50 | else if(i ==0) { //this is same as because we wont reach this part if they are not equal, this.pattern.charAt(i) != this.pattern.charAt(j) && i ==0 |
| 51 | this.lps[j] = 0; |
| 52 | j++; |
| 53 | } |
| 54 | else { |
| 55 | i = this.lps[i-1]; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | public class Main{ |
| 61 | public static void main(String args[]) { |