更新0005.最长回文子串.md

This commit is contained in:
jinyuhang-007
2022-02-27 17:35:50 -08:00
parent b07dba43a8
commit 9712e3f75c

View File

@ -260,7 +260,26 @@ public:
# 其他语言版本 # 其他语言版本
## Java 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);
}
map.put(nums[i], i);
}
return res;
}
```
```java ```java
// 双指针 中心扩散法 // 双指针 中心扩散法
@ -291,7 +310,7 @@ class Solution {
} }
``` ```
## Python Python
```python ```python
class Solution: class Solution:
@ -312,7 +331,8 @@ class Solution:
return s[left:right + 1] return s[left:right + 1]
``` ```
> 双指针 双指针:
```python ```python
class Solution: class Solution:
def longestPalindrome(self, s: str) -> str: def longestPalindrome(self, s: str) -> str:
@ -340,13 +360,13 @@ class Solution:
return s[start:end] return s[start:end]
``` ```
## Go Go
```go ```go
``` ```
## JavaScript JavaScript
```js ```js
//动态规划解法 //动态规划解法
@ -462,8 +482,9 @@ var longestPalindrome = function(s) {
}; };
``` ```
## C C
动态规划:
动态规划:
```c ```c
//初始化dp数组全部初始为false //初始化dp数组全部初始为false
bool **initDP(int strLen) { bool **initDP(int strLen) {
@ -513,7 +534,7 @@ char * longestPalindrome(char * s){
} }
``` ```
双指针: 双指针
```c ```c
int left, maxLength; int left, maxLength;
void extend(char *str, int i, int j, int size) { void extend(char *str, int i, int j, int size) {