Problems:
https://leetcode.com/problems/longest-palindromic-substring/
Solution1:
two points
class Solution {
public String longestPalindrome(String s) {
char[] chars = s.toCharArray();
int len = s.length();
while (len >= 0) {
for (int i = 0; i + len -1 < chars.length; i++) {
int left = i;
int right = i + len - 1;
boolean flag = true;
// applying two points
while (left < right) {
if (chars[left] != chars[right]) {
flag = false;
break;
}
left++;
right--;
}
if (flag) {
return s.substring(i, i+len);
}
}
len--;
}
return "";
}
}
tbc
734




被折叠的 条评论
为什么被折叠?



