20250108
This commit is contained in:
49
1960.两个回文子字符串长度的最大乘积.java
Normal file
49
1960.两个回文子字符串长度的最大乘积.java
Normal file
@@ -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<Integer> stringAsciiList = conv2ascii(s);
|
||||||
|
List<Integer> 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<Integer> conv2ascii(String s) {
|
||||||
|
List<Integer> 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
|
||||||
Reference in New Issue
Block a user