Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 5 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Aug 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
05 最长回文子串
更新Java动态绘画方法, 之前的根本就不是这个题
  • Loading branch information
AronJudge committed Aug 20, 2022
commit b2534f7993018e497670e05fdf258830a1f4b69b
44 changes: 31 additions & 13 deletions problems/0005.最长回文子串.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,39 @@ public:
Java:

```java
public int[] twoSum(int[] nums, int target) {
int[] res = new int[2];
if(nums == null || nums.length == 0){
return res;
}
Map<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < nums.length; i++){
int temp = target - nums[i];
if(map.containsKey(temp)){
res[1] = i;
res[0] = map.get(temp);
// 双指针 动态规划
class Solution {
public String longestPalindrome(String s) {
if (s.length() == 0 || s.length() == 1) return s;
int length = 1;
int index = 0;
boolean[][] palindrome = new boolean[s.length()][s.length()];
for (int i = 0; i < s.length(); i++) {
palindrome[i][i] = true;
}

for (int L = 2; L <= s.length(); L++) {
for (int i = 0; i < s.length(); i++) {
int j = i + L - 1;
if (j >= s.length()) break;

if (s.charAt(i) != s.charAt(j)) {
palindrome[i][j] = false;
} else {
if (j - i < 3) {
palindrome[i][j] = true;
} else {
palindrome[i][j] = palindrome[i + 1][j - 1];
}
}
if (palindrome[i][j] && j - i + 1 > length) {
length = j - i + 1;
index = i;
}
}
}
map.put(nums[i], i);
return s.substring(index, index + length);
}
return res;
}
```

Expand Down

AltStyle によって変換されたページ (->オリジナル) /