From 362d4ad584263cb79f6d4c7b97f63470114e0590 Mon Sep 17 00:00:00 2001 From: oasis Date: Wed, 8 Jan 2025 14:49:41 +0800 Subject: [PATCH] 20250108 --- 1960.两个回文子字符串长度的最大乘积.java | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 1960.两个回文子字符串长度的最大乘积.java diff --git a/1960.两个回文子字符串长度的最大乘积.java b/1960.两个回文子字符串长度的最大乘积.java new file mode 100644 index 0000000..7ea8a29 --- /dev/null +++ b/1960.两个回文子字符串长度的最大乘积.java @@ -0,0 +1,49 @@ +/* + * @lc app=leetcode.cn id=1960 lang=java + * + * [1960] 两个回文子字符串长度的最大乘积 + */ + +// @lc code=start + +import java.util.ArrayList; +import java.util.List; + +class Solution { + public long maxProduct(String s) { + List stringAsciiList = conv2ascii(s); + List stringAndList = new ArrayList<>(); + int listLength = stringAsciiList.size(); + for (int i = 0; i < listLength; i++) { + int a = stringAsciiList.get(i) + stringAsciiList.get(listLength - 1 - i); + int b = stringAsciiList.get(i) * 2; + stringAndList.add(a == b ? 1 : 0); + } + System.out.println(stringAndList); + + return 0; + + } + + /** + * 获取字符串的ascii码字符串 + * + * @param s + * @return + */ + private List conv2ascii(String s) { + List stringAsciiList = new ArrayList<>(); + for (char item : s.toCharArray()) { + stringAsciiList.add((int) item); + }; + return stringAsciiList; + + } + + public static void main(String[] args) { + Solution solution = new Solution(); + solution.maxProduct("ababbb"); + } + +} +// @lc code=end