-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob459.java
More file actions
54 lines (47 loc) · 1.09 KB
/
prob459.java
File metadata and controls
54 lines (47 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Solution {
public boolean repeatedSubstringPattern(String s) {
int n=s.length();
int[]arr=new int[n];
int idx=1;
int len = 0;
arr[0] = 0;
while (idx < n) //lps array construction
{
if (s.charAt(idx) == s.charAt(len))
{
len++;
arr[idx] = len;
idx++;
}
else
{
if (len != 0)
{
len = arr[len-1];
}
else
{
arr[idx] = 0;
idx++;
}
}
}
for(int i=0;i<n;i++){
System.out.print(arr[i]+" ");
}
boolean flag=false;
idx=n-1;
idx=n-arr[n-1]-1; //all verification steps now.
if(idx==n-1)
return false;
int e=idx;
len=e+1;
if(n%len!=0)
return false;
for(int i=idx+1;i<n;i++){
if(arr[i]==0)
return false;
}
return true;
}
}