From b8dec4a24ecf9f1700fcdce83eed87e1668d8197 Mon Sep 17 00:00:00 2001 From: Samarth Swami Date: Sun, 20 Jul 2025 19:06:30 +0530 Subject: [PATCH 01/10] feat: add solutions to lc problem: No.1960 --- .../README.md | 207 +++++++++++++++++- .../README_EN.md | 206 ++++++++++++++++- .../solution..java | 53 +++++ .../solution.cpp | 37 ++++ .../solution.go | 71 ++++++ .../solution.py | 34 +++ 6 files changed, 601 insertions(+), 7 deletions(-) create mode 100644 solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution..java create mode 100644 solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.cpp create mode 100644 solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.go create mode 100644 solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.py diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md index b918ee2cb015b..a188265b21356 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md @@ -5,9 +5,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1900-1999/1960.Ma rating: 2690 source: 第 58 场双周赛 Q4 tags: - - 字符串 - - 哈希函数 - - 滚动哈希 + - 字符串 + - 哈希函数 + - 滚动哈希 --- @@ -69,28 +69,227 @@ tags: ```python +class Solution: + def maxProduct(self, s: str) -> int: + n = len(s) + hlen = [0] * n + center = right = 0 + + for i in range(n): + if i < right: + hlen[i] = min(right - i, hlen[2 * center - i]) + while ( + 0 <= i - 1 - hlen[i] + and i + 1 + hlen[i] < len(s) + and s[i - 1 - hlen[i]] == s[i + 1 + hlen[i]] + ): + hlen[i] += 1 + if right < i + hlen[i]: + center, right = i, i + hlen[i] + + prefix = [0] * n + suffix = [0] * n + + for i in range(n): + prefix[i + hlen[i]] = max(prefix[i + hlen[i]], 2 * hlen[i] + 1) + suffix[i - hlen[i]] = max(suffix[i - hlen[i]], 2 * hlen[i] + 1) + + for i in range(1, n): + prefix[~i] = max(prefix[~i], prefix[~i + 1] - 2) + suffix[i] = max(suffix[i], suffix[i - 1] - 2) + + for i in range(1, n): + prefix[i] = max(prefix[i - 1], prefix[i]) + suffix[~i] = max(suffix[~i], suffix[~i + 1]) + + return max(prefix[i - 1] * suffix[i] for i in range(1, n)) + ``` #### Java ```java +class Solution { + public long maxProduct(String s) { + int n = s.length(); + if (n == 2) return 1; + int[] len = manachers(s); + long[] left = new long[n]; + int max = 1; + left[0] = max; + for (int i = 1; i <= n - 1; i++) { + if (len[(i - max - 1 + i) / 2] > max) max += 2; + left[i] = max; + } + max = 1; + long[] right = new long[n]; + right[n - 1] = max; + for (int i = n - 2; i >= 0; i--) { + if (len[(i + max + 1 + i) / 2] > max) max += 2; + right[i] = max; + } + long res = 1; + for (int i = 1; i < n; i++) { + res = Math.max(res, left[i - 1] * right[i]); + } + return res; + } + private int[] manachers(String s) { + int len = s.length(); + int[] P = new int[len]; + int c = 0; + int r = 0; + for (int i = 0; i < len; i++) { + int mirror = (2 * c) - i; + if (i < r) { + P[i] = Math.min(r - i, P[mirror]); + } + int a = i + (1 + P[i]); + int b = i - (1 + P[i]); + while (a < len && b >= 0 && s.charAt(a) == s.charAt(b)) { + P[i]++; + a++; + b--; + } + if (i + P[i] > r) { + c = i; + r = i + P[i]; + } + } + for (int i = 0; i < len; i++) { + P[i] = 1 + 2 * P[i]; + } + return P; + } +} + ``` #### C++ ```cpp +class Solution { +public: + long long maxProduct(string s) { + long long res = 0, l = 0, n = s.size(); + vector m(n), r(n); + + for (int i = 0, l = 0, r = -1; i < n; ++i) { + int k = (i > r) ? 1 : min(m[l + r - i], r - i + 1); + while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) + k++; + m[i] = k--; + if (i + k > r) { + l = i - k; + r = i + k; + } + } + + queue> q, q1; + + for (int i = n - 1; i >= 0; --i) { + while (!q.empty() && q.front()[0] - q.front()[1] > i - 1) + q.pop(); + r[i] = 1 + (q.empty() ? 0 : (q.front()[0] - i) * 2); + q.push({i, m[i]}); + } + + for (int i = 0; i < n - 1; i++) { + while (!q1.empty() && q1.front()[0] + q1.front()[1] < i + 1) + q1.pop(); + l = max(l, 1ll + (q1.empty() ? 0 : (i - q1.front()[0]) * 2)); + res = max(res, l * r[i + 1]); + q1.push({i, m[i]}); + } + + return res; + } +}; + ``` #### Go ```go +func maxProduct(s string) int64 { + n := len(s) + hlen := make([]int, n) + center, right := 0, 0 + + for i := 0; i < n; i++ { + if i < right { + mirror := 2*center - i + if mirror >= 0 && mirror < n { + hlen[i] = min(right-i, hlen[mirror]) + } + } + for i-1-hlen[i] >= 0 && i+1+hlen[i] < n && s[i-1-hlen[i]] == s[i+1+hlen[i]] { + hlen[i]++ + } + if i+hlen[i] > right { + center = i + right = i + hlen[i] + } + } + + prefix := make([]int, n) + suffix := make([]int, n) + + for i := 0; i < n; i++ { + r := i + hlen[i] + if r < n { + prefix[r] = max(prefix[r], 2*hlen[i]+1) + } + l := i - hlen[i] + if l >= 0 { + suffix[l] = max(suffix[l], 2*hlen[i]+1) + } + } + + for i := 1; i < n; i++ { + if n-i-1 >= 0 { + prefix[n-i-1] = max(prefix[n-i-1], prefix[n-i]-2) + } + suffix[i] = max(suffix[i], suffix[i-1]-2) + } + + for i := 1; i < n; i++ { + prefix[i] = max(prefix[i-1], prefix[i]) + suffix[n-i-1] = max(suffix[n-i], suffix[n-i-1]) + } + + var res int64 + for i := 1; i < n; i++ { + prod := int64(prefix[i-1]) * int64(suffix[i]) + if prod > res { + res = prod + } + } + + return res +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +func min(a, b int) int { + if a < b { + return a + } + return b +} + ``` - + \ No newline at end of file diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md index 044c570412d56..25ed9132234c7 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md @@ -5,9 +5,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1900-1999/1960.Ma rating: 2690 source: Biweekly Contest 58 Q4 tags: - - String - - Hash Function - - Rolling Hash + - String + - Hash Function + - Rolling Hash --- @@ -67,24 +67,224 @@ tags: ```python +class Solution: + def maxProduct(self, s: str) -> int: + n = len(s) + hlen = [0] * n + center = right = 0 + + for i in range(n): + if i < right: + hlen[i] = min(right - i, hlen[2 * center - i]) + while ( + 0 <= i - 1 - hlen[i] + and i + 1 + hlen[i] < len(s) + and s[i - 1 - hlen[i]] == s[i + 1 + hlen[i]] + ): + hlen[i] += 1 + if right < i + hlen[i]: + center, right = i, i + hlen[i] + + prefix = [0] * n + suffix = [0] * n + + for i in range(n): + prefix[i + hlen[i]] = max(prefix[i + hlen[i]], 2 * hlen[i] + 1) + suffix[i - hlen[i]] = max(suffix[i - hlen[i]], 2 * hlen[i] + 1) + + for i in range(1, n): + prefix[~i] = max(prefix[~i], prefix[~i + 1] - 2) + suffix[i] = max(suffix[i], suffix[i - 1] - 2) + + for i in range(1, n): + prefix[i] = max(prefix[i - 1], prefix[i]) + suffix[~i] = max(suffix[~i], suffix[~i + 1]) + + return max(prefix[i - 1] * suffix[i] for i in range(1, n)) + + ``` #### Java ```java +class Solution { + public long maxProduct(String s) { + int n = s.length(); + if (n == 2) return 1; + int[] len = manachers(s); + long[] left = new long[n]; + int max = 1; + left[0] = max; + for (int i = 1; i <= n - 1; i++) { + if (len[(i - max - 1 + i) / 2] > max) max += 2; + left[i] = max; + } + max = 1; + long[] right = new long[n]; + right[n - 1] = max; + for (int i = n - 2; i >= 0; i--) { + if (len[(i + max + 1 + i) / 2] > max) max += 2; + right[i] = max; + } + long res = 1; + for (int i = 1; i < n; i++) { + res = Math.max(res, left[i - 1] * right[i]); + } + return res; + } + private int[] manachers(String s) { + int len = s.length(); + int[] P = new int[len]; + int c = 0; + int r = 0; + for (int i = 0; i < len; i++) { + int mirror = (2 * c) - i; + if (i < r) { + P[i] = Math.min(r - i, P[mirror]); + } + int a = i + (1 + P[i]); + int b = i - (1 + P[i]); + while (a < len && b >= 0 && s.charAt(a) == s.charAt(b)) { + P[i]++; + a++; + b--; + } + if (i + P[i] > r) { + c = i; + r = i + P[i]; + } + } + for (int i = 0; i < len; i++) { + P[i] = 1 + 2 * P[i]; + } + return P; + } +} + ``` #### C++ ```cpp +class Solution { +public: + long long maxProduct(string s) { + long long res = 0, l = 0, n = s.size(); + vector m(n), r(n); + + for (int i = 0, l = 0, r = -1; i < n; ++i) { + int k = (i > r) ? 1 : min(m[l + r - i], r - i + 1); + while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) + k++; + m[i] = k--; + if (i + k > r) { + l = i - k; + r = i + k; + } + } + + queue> q, q1; + + for (int i = n - 1; i >= 0; --i) { + while (!q.empty() && q.front()[0] - q.front()[1] > i - 1) + q.pop(); + r[i] = 1 + (q.empty() ? 0 : (q.front()[0] - i) * 2); + q.push({i, m[i]}); + } + + for (int i = 0; i < n - 1; i++) { + while (!q1.empty() && q1.front()[0] + q1.front()[1] < i + 1) + q1.pop(); + l = max(l, 1ll + (q1.empty() ? 0 : (i - q1.front()[0]) * 2)); + res = max(res, l * r[i + 1]); + q1.push({i, m[i]}); + } + + return res; + } +}; + ``` #### Go ```go +func maxProduct(s string) int64 { + n := len(s) + hlen := make([]int, n) + center, right := 0, 0 + + for i := 0; i < n; i++ { + if i < right { + mirror := 2*center - i + if mirror >= 0 && mirror < n { + hlen[i] = min(right-i, hlen[mirror]) + } + } + for i-1-hlen[i] >= 0 && i+1+hlen[i] < n && s[i-1-hlen[i]] == s[i+1+hlen[i]] { + hlen[i]++ + } + if i+hlen[i] > right { + center = i + right = i + hlen[i] + } + } + + prefix := make([]int, n) + suffix := make([]int, n) + + for i := 0; i < n; i++ { + r := i + hlen[i] + if r < n { + prefix[r] = max(prefix[r], 2*hlen[i]+1) + } + l := i - hlen[i] + if l >= 0 { + suffix[l] = max(suffix[l], 2*hlen[i]+1) + } + } + + for i := 1; i < n; i++ { + if n-i-1 >= 0 { + prefix[n-i-1] = max(prefix[n-i-1], prefix[n-i]-2) + } + suffix[i] = max(suffix[i], suffix[i-1]-2) + } + + for i := 1; i < n; i++ { + prefix[i] = max(prefix[i-1], prefix[i]) + suffix[n-i-1] = max(suffix[n-i], suffix[n-i-1]) + } + + var res int64 + for i := 1; i < n; i++ { + prod := int64(prefix[i-1]) * int64(suffix[i]) + if prod > res { + res = prod + } + } + + return res +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +func min(a, b int) int { + if a < b { + return a + } + return b +} + ``` diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution..java b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution..java new file mode 100644 index 0000000000000..7f6946576cbae --- /dev/null +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution..java @@ -0,0 +1,53 @@ +class Solution { + public long maxProduct(String s) { + int n = s.length(); + if (n == 2) return 1; + int[] len = manachers(s); + long[] left = new long[n]; + int max = 1; + left[0] = max; + for (int i = 1; i <= n - 1; i++) { + if (len[(i - max - 1 + i) / 2] > max) max += 2; + left[i] = max; + } + max = 1; + long[] right = new long[n]; + right[n - 1] = max; + for (int i = n - 2; i >= 0; i--) { + if (len[(i + max + 1 + i) / 2] > max) max += 2; + right[i] = max; + } + long res = 1; + for (int i = 1; i < n; i++) { + res = Math.max(res, left[i - 1] * right[i]); + } + return res; + } + private int[] manachers(String s) { + int len = s.length(); + int[] P = new int[len]; + int c = 0; + int r = 0; + for (int i = 0; i < len; i++) { + int mirror = (2 * c) - i; + if (i < r) { + P[i] = Math.min(r - i, P[mirror]); + } + int a = i + (1 + P[i]); + int b = i - (1 + P[i]); + while (a < len && b >= 0 && s.charAt(a) == s.charAt(b)) { + P[i]++; + a++; + b--; + } + if (i + P[i] > r) { + c = i; + r = i + P[i]; + } + } + for (int i = 0; i < len; i++) { + P[i] = 1 + 2 * P[i]; + } + return P; + } +} diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.cpp b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.cpp new file mode 100644 index 0000000000000..c287fd98d7883 --- /dev/null +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.cpp @@ -0,0 +1,37 @@ +class Solution { +public: + long long maxProduct(string s) { + long long res = 0, l = 0, n = s.size(); + vector m(n), r(n); + + for (int i = 0, l = 0, r = -1; i < n; ++i) { + int k = (i > r) ? 1 : min(m[l + r - i], r - i + 1); + while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) + k++; + m[i] = k--; + if (i + k > r) { + l = i - k; + r = i + k; + } + } + + queue> q, q1; + + for (int i = n - 1; i >= 0; --i) { + while (!q.empty() && q.front()[0] - q.front()[1] > i - 1) + q.pop(); + r[i] = 1 + (q.empty() ? 0 : (q.front()[0] - i) * 2); + q.push({i, m[i]}); + } + + for (int i = 0; i < n - 1; i++) { + while (!q1.empty() && q1.front()[0] + q1.front()[1] < i + 1) + q1.pop(); + l = max(l, 1ll + (q1.empty() ? 0 : (i - q1.front()[0]) * 2)); + res = max(res, l * r[i + 1]); + q1.push({i, m[i]}); + } + + return res; + } +}; diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.go b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.go new file mode 100644 index 0000000000000..b323a2ddcc6f6 --- /dev/null +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.go @@ -0,0 +1,71 @@ +func maxProduct(s string) int64 { + n := len(s) + hlen := make([]int, n) + center, right := 0, 0 + + for i := 0; i < n; i++ { + if i < right { + mirror := 2*center - i + if mirror >= 0 && mirror < n { + hlen[i] = min(right-i, hlen[mirror]) + } + } + for i-1-hlen[i] >= 0 && i+1+hlen[i] < n && s[i-1-hlen[i]] == s[i+1+hlen[i]] { + hlen[i]++ + } + if i+hlen[i] > right { + center = i + right = i + hlen[i] + } + } + + prefix := make([]int, n) + suffix := make([]int, n) + + for i := 0; i < n; i++ { + r := i + hlen[i] + if r < n { + prefix[r] = max(prefix[r], 2*hlen[i]+1) + } + l := i - hlen[i] + if l >= 0 { + suffix[l] = max(suffix[l], 2*hlen[i]+1) + } + } + + for i := 1; i < n; i++ { + if n-i-1 >= 0 { + prefix[n-i-1] = max(prefix[n-i-1], prefix[n-i]-2) + } + suffix[i] = max(suffix[i], suffix[i-1]-2) + } + + for i := 1; i < n; i++ { + prefix[i] = max(prefix[i-1], prefix[i]) + suffix[n-i-1] = max(suffix[n-i], suffix[n-i-1]) + } + + var res int64 + for i := 1; i < n; i++ { + prod := int64(prefix[i-1]) * int64(suffix[i]) + if prod > res { + res = prod + } + } + + return res +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} + +func min(a, b int) int { + if a < b { + return a + } + return b +} diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.py b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.py new file mode 100644 index 0000000000000..196786c37fecd --- /dev/null +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.py @@ -0,0 +1,34 @@ +class Solution: + def maxProduct(self, s: str) -> int: + n = len(s) + hlen = [0] * n + center = right = 0 + + for i in range(n): + if i < right: + hlen[i] = min(right - i, hlen[2 * center - i]) + while ( + 0 <= i - 1 - hlen[i] + and i + 1 + hlen[i] < len(s) + and s[i - 1 - hlen[i]] == s[i + 1 + hlen[i]] + ): + hlen[i] += 1 + if right < i + hlen[i]: + center, right = i, i + hlen[i] + + prefix = [0] * n + suffix = [0] * n + + for i in range(n): + prefix[i + hlen[i]] = max(prefix[i + hlen[i]], 2 * hlen[i] + 1) + suffix[i - hlen[i]] = max(suffix[i - hlen[i]], 2 * hlen[i] + 1) + + for i in range(1, n): + prefix[~i] = max(prefix[~i], prefix[~i + 1] - 2) + suffix[i] = max(suffix[i], suffix[i - 1] - 2) + + for i in range(1, n): + prefix[i] = max(prefix[i - 1], prefix[i]) + suffix[~i] = max(suffix[~i], suffix[~i + 1]) + + return max(prefix[i - 1] * suffix[i] for i in range(1, n)) From 6456b6a3cbfde4e8e4fe3ad58738dcd4e11d4740 Mon Sep 17 00:00:00 2001 From: samarthswami1016 <70163465+samarthswami1016@users.noreply.github.com> Date: Sun, 20 Jul 2025 15:24:49 +0000 Subject: [PATCH 02/10] style: format code and docs with prettier --- .../README.md | 8 ++++---- .../README_EN.md | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md index a188265b21356..5076cfb5e8fa4 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md @@ -5,9 +5,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1900-1999/1960.Ma rating: 2690 source: 第 58 场双周赛 Q4 tags: - - 字符串 - - 哈希函数 - - 滚动哈希 + - 字符串 + - 哈希函数 + - 滚动哈希 --- @@ -292,4 +292,4 @@ func min(a, b int) int { - \ No newline at end of file + diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md index 25ed9132234c7..566dbdcaab300 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md @@ -5,9 +5,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/1900-1999/1960.Ma rating: 2690 source: Biweekly Contest 58 Q4 tags: - - String - - Hash Function - - Rolling Hash + - String + - Hash Function + - Rolling Hash --- From 2f2b1da34090dbdcf99492757123ae5b2f5395e5 Mon Sep 17 00:00:00 2001 From: Samarth Swami Date: Tue, 22 Jul 2025 14:27:18 +0530 Subject: [PATCH 03/10] Rename solution..java to Solution..java --- .../{solution..java => Solution..java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/{solution..java => Solution..java} (100%) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution..java b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution..java similarity index 100% rename from solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution..java rename to solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution..java From 3833ea4128e0d11dc5e349ec2b259bc18ba6fd08 Mon Sep 17 00:00:00 2001 From: Samarth Swami Date: Tue, 22 Jul 2025 14:27:54 +0530 Subject: [PATCH 04/10] Rename solution.py to Solution.py --- .../{solution.py => Solution.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/{solution.py => Solution.py} (100%) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.py b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.py similarity index 100% rename from solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.py rename to solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.py From 9667fd4268081b92751f9739c3dba5eddda8509c Mon Sep 17 00:00:00 2001 From: Samarth Swami Date: Tue, 22 Jul 2025 14:28:28 +0530 Subject: [PATCH 05/10] Rename solution.cpp to Solution.cpp --- .../{solution.cpp => Solution.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/{solution.cpp => Solution.cpp} (100%) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.cpp b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.cpp similarity index 100% rename from solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.cpp rename to solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.cpp From 213b18df56b4a6e365b6fd89fc165dbe09f301e6 Mon Sep 17 00:00:00 2001 From: Samarth Swami Date: Tue, 22 Jul 2025 14:28:49 +0530 Subject: [PATCH 06/10] Rename solution.go to Solution.go --- .../{solution.go => Solution.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/{solution.go => Solution.go} (100%) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.go b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.go similarity index 100% rename from solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/solution.go rename to solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.go From 505a70673feecfd958f047e0e03517c345a24aac Mon Sep 17 00:00:00 2001 From: Samarth Swami Date: Tue, 22 Jul 2025 14:29:12 +0530 Subject: [PATCH 07/10] Rename Solution..java to Solution.java --- .../{Solution..java => Solution.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/{Solution..java => Solution.java} (100%) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution..java b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.java similarity index 100% rename from solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution..java rename to solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.java From d5c7d54b186480b4a44a9bbcc8851be006c7e2b2 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Wed, 23 Jul 2025 06:59:36 +0800 Subject: [PATCH 08/10] Update Solution.go --- .../Solution.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.go b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.go index b323a2ddcc6f6..56fa1a39b45cb 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.go +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/Solution.go @@ -55,17 +55,3 @@ func maxProduct(s string) int64 { return res } - -func max(a, b int) int { - if a > b { - return a - } - return b -} - -func min(a, b int) int { - if a < b { - return a - } - return b -} From f098f2914f244fb24694b193872200b232fca89d Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Wed, 23 Jul 2025 07:00:14 +0800 Subject: [PATCH 09/10] Update README.md --- .../README.md | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md index 5076cfb5e8fa4..f80ef7a0f97eb 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README.md @@ -68,7 +68,6 @@ tags: #### Python3 ```python - class Solution: def maxProduct(self, s: str) -> int: n = len(s) @@ -103,13 +102,11 @@ class Solution: suffix[~i] = max(suffix[~i], suffix[~i + 1]) return max(prefix[i - 1] * suffix[i] for i in range(1, n)) - ``` #### Java ```java - class Solution { public long maxProduct(String s) { int n = s.length(); @@ -163,13 +160,11 @@ class Solution { return P; } } - ``` #### C++ ```cpp - class Solution { public: long long maxProduct(string s) { @@ -207,13 +202,11 @@ public: return res; } }; - ``` #### Go ```go - func maxProduct(s string) int64 { n := len(s) hlen := make([]int, n) @@ -271,21 +264,6 @@ func maxProduct(s string) int64 { return res } - -func max(a, b int) int { - if a > b { - return a - } - return b -} - -func min(a, b int) int { - if a < b { - return a - } - return b -} - ``` From 54aa98dd0fe7a3a4f0e5424a3aecd8f5322ea792 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Wed, 23 Jul 2025 07:00:51 +0800 Subject: [PATCH 10/10] Update README_EN.md --- .../README_EN.md | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md index 566dbdcaab300..7959a940d8336 100644 --- a/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md +++ b/solution/1900-1999/1960.Maximum Product of the Length of Two Palindromic Substrings/README_EN.md @@ -66,7 +66,6 @@ tags: #### Python3 ```python - class Solution: def maxProduct(self, s: str) -> int: n = len(s) @@ -101,14 +100,11 @@ class Solution: suffix[~i] = max(suffix[~i], suffix[~i + 1]) return max(prefix[i - 1] * suffix[i] for i in range(1, n)) - - ``` #### Java ```java - class Solution { public long maxProduct(String s) { int n = s.length(); @@ -162,13 +158,11 @@ class Solution { return P; } } - ``` #### C++ ```cpp - class Solution { public: long long maxProduct(string s) { @@ -206,13 +200,11 @@ public: return res; } }; - ``` #### Go ```go - func maxProduct(s string) int64 { n := len(s) hlen := make([]int, n) @@ -270,21 +262,6 @@ func maxProduct(s string) int64 { return res } - -func max(a, b int) int { - if a > b { - return a - } - return b -} - -func min(a, b int) int { - if a < b { - return a - } - return b -} - ```