MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/medium/_0005/Solution.java:11–72  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/11/04 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class Solution {
12// int st, end;
13//
14// public String longestPalindrome(String s) {
15//// st = 0;
16//// end = 0;
17// int len = s.length();
18// if (len <= 1) return s;
19// char[] chars = s.toCharArray();
20// for (int i = 0; i < len; i++) {
21// helper(chars, i, i);
22// helper(chars, i, i + 1);
23// }
24// return s.substring(st, end + 1);
25// }
26//
27// private void helper(char[] chars, int l, int r) {
28// while (l >= 0 && r < chars.length && chars[l] == chars[r]) {
29// --l;
30// ++r;
31// }
32// if (end - st < r - l - 2) {
33// st = l + 1;
34// end = r - 1;
35// }
36// }
37
38// public String longestPalindrome(String s) {
39// int len = s.length();
40// if (len <= 1) return s;
41// int st = 0, end = 0;
42// char[] chars = s.toCharArray();
43// boolean[][] dp = new boolean[len][len];
44// for (int i = 0; i < len; i++) {
45// dp[i][i] = true;
46// for (int j = 0; j < i; j++) {
47// if (j + 1 == i) {
48// dp[j][i] = chars[j] == chars[i];
49// } else {
50// dp[j][i] = dp[j + 1][i - 1] && chars[j] == chars[i];
51// }
52// if (dp[j][i] && i - j > end - st) {
53// st = j;
54// end = i;
55// }
56// }
57// }
58// return s.substring(st, end + 1);
59// }
60
61 public String longestPalindrome(String s) {
62
63 return s;
64 }
65
66 public static void main(String[] args) {
67 Solution solution = new Solution();
68 System.out.println(solution.longestPalindrome("babad"));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected