ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
Sir, use different colours while writing, it is looking clumsy after a blink...😅
@@spartaninfo3273 Noted, will check on this.
JAVA Code : public static int minChar(String s) { // Write your code here String rev = new StringBuilder(s).reverse().toString(); String newStr = s + "$" + rev; int[] lps = computeLPS(newStr); int N = newStr.length(); return s.length() - lps[N - 1]; } static int[] computeLPS(String newStr){ int N = newStr.length(); int j = 0; int i = 1; int[] lps = new int[N]; lps[0] = 0; while(i < N){ if(newStr.charAt(i) == newStr.charAt(j)){ lps[i] = j + 1; ++i; ++j; } else{ if(j != 0){ j = lps[j - 1]; } else{ lps[i] = 0; i++; } } } return lps; }
Sir, use different colours while writing, it is looking clumsy after a blink...😅
@@spartaninfo3273 Noted, will check on this.
JAVA Code :
public static int minChar(String s) {
// Write your code here
String rev = new StringBuilder(s).reverse().toString();
String newStr = s + "$" + rev;
int[] lps = computeLPS(newStr);
int N = newStr.length();
return s.length() - lps[N - 1];
}
static int[] computeLPS(String newStr){
int N = newStr.length();
int j = 0;
int i = 1;
int[] lps = new int[N];
lps[0] = 0;
while(i < N){
if(newStr.charAt(i) == newStr.charAt(j)){
lps[i] = j + 1;
++i;
++j;
}
else{
if(j != 0){
j = lps[j - 1];
}
else{
lps[i] = 0;
i++;
}
}
}
return lps;
}