mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 17:29:31 +08:00
refactor: LongestPalindromicSubstring
(#5420)
* refactor: LongestPalindromicSubstring * checkstyle: fix formatting --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
@ -1,25 +1,18 @@
|
||||
package com.thealgorithms.dynamicprogramming;
|
||||
|
||||
/*
|
||||
* Algorithm explanation https://leetcode.com/problems/longest-palindromic-substring/
|
||||
/**
|
||||
* Class for finding the longest palindromic substring within a given string.
|
||||
* <p>
|
||||
* A palindromic substring is a sequence of characters that reads the same backward as forward.
|
||||
* This class uses a dynamic programming approach to efficiently find the longest palindromic substring.
|
||||
*
|
||||
*/
|
||||
public final class LongestPalindromicSubstring {
|
||||
private LongestPalindromicSubstring() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String a = "babad";
|
||||
String b = "cbbd";
|
||||
|
||||
String aLPS = lps(a);
|
||||
String bLPS = lps(b);
|
||||
|
||||
System.out.println(a + " => " + aLPS);
|
||||
System.out.println(b + " => " + bLPS);
|
||||
}
|
||||
|
||||
private static String lps(String input) {
|
||||
if (input == null || input.length() == 0) {
|
||||
public static String lps(String input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return input;
|
||||
}
|
||||
boolean[][] arr = new boolean[input.length()][input.length()];
|
||||
|
Reference in New Issue
Block a user