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
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 30 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,38 @@ 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
21 changes: 21 additions & 0 deletions problems/0463.岛屿的周长.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ class Solution {
return res;
}
}

// 解法二
class Solution {
public int islandPerimeter(int[][] grid) {
// 计算岛屿的周长
// 方法二 : 遇到相邻的陆地总周长就-2
int landSum = 0; // 陆地数量
int cover = 0; // 相邻陆地数量
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[0].length; j++) {
if (grid[i][j] == 1) {
landSum++;
// 统计上面和左边的相邻陆地
if(i - 1 >= 0 && grid[i-1][j] == 1) cover++;
if(j - 1 >= 0 && grid[i][j-1] == 1) cover++;
}
}
}
return landSum * 4 - cover * 2;
}
}
```

Python:
Expand Down

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