1
1
/*
2
- * Problem: Longest Palindromic Substring
2
+ * Problem: 5. Longest Palindromic Substring
3
3
* Acceptance Rate: 31.0%
4
4
* URL: https://leetcode.com/problems/longest-palindromic-substring/
5
5
*
6
6
* Runtime: 96 ms, faster than 96.82% of TypeScript online submissions for Longest Palindromic Substring.
7
7
* Memory Usage: 41.9 MB, less than 65.68% of TypeScript online submissions for Longest Palindromic Substring.
8
8
*/
9
9
10
- export default class Solution {
10
+ export default function longestPalindromeIn ( s : string ) : string {
11
+ // let result = Solution.findLongestPalindrome(s);
12
+ // console.log(s, "->", result);
13
+ // return result;
14
+
15
+ return Solution . findLongestPalindrome ( s ) ;
16
+ } ;
17
+
18
+ class Solution {
11
19
12
20
private static startIndex : number ;
13
21
private static palindromeLength : number ;
@@ -26,13 +34,13 @@ export default class Solution {
26
34
return s . substring ( Solution . startIndex , Solution . startIndex + Solution . palindromeLength ) ;
27
35
} ;
28
36
29
- private static extendPalindromeEvenLength ( s : string , startingIndex : number ) {
30
- let left = startingIndex , right = startingIndex + 1 ;
37
+ private static extendPalindromeOddLength ( s : string , startingIndex : number ) {
38
+ let left = startingIndex , right = startingIndex ;
31
39
Solution . extendPalindrome ( s , left , right ) ;
32
40
}
33
41
34
- private static extendPalindromeOddLength ( s : string , startingIndex : number ) {
35
- let left = startingIndex , right = startingIndex ;
42
+ private static extendPalindromeEvenLength ( s : string , startingIndex : number ) {
43
+ let left = startingIndex , right = startingIndex + 1 ;
36
44
Solution . extendPalindrome ( s , left , right ) ;
37
45
}
38
46
@@ -65,14 +73,6 @@ export default class Solution {
65
73
}
66
74
}
67
75
68
- function longestPalindromeIn ( s : string ) : string {
69
- let result = Solution . findLongestPalindrome ( s ) ;
70
-
71
- console . log ( s , "->" , result ) ;
72
-
73
- return result ;
74
- } ;
75
-
76
76
//---------------------------------------------------------------------
77
77
// ---------- MAIN PROGRAM ----------
78
78
//---------------------------------------------------------------------
@@ -82,7 +82,7 @@ if(import.meta.main) {
82
82
longestPalindromeIn ( "cbbd" ) ;
83
83
longestPalindromeIn ( "weloveracecars" ) ;
84
84
85
- // RUN: deno run Medium /LongestPalindromicSubstring.ts
85
+ // RUN: deno run medium /LongestPalindromicSubstring.ts
86
86
}
87
87
88
88
// --------------------------- Terminal Output: ---------------------------
0 commit comments