KMP prefix table
Java
Hard
5 views
Problem Description
Task: build prefix function (lps) for pattern char array (classic KMP).
Output Format
Return value
Official Solution
static int[] lps(char[] p){int n=p.length;int[] l=new int[n];int i=1,len=0;while(i<n){if(p[i]==p[len]){l[i++]=++len;}else if(len>0){len=l[len-1];}else{l[i++]=0;}}return l;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!