mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
@ -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
|
||||
// 双指针 中心扩散法
|
||||
@ -291,7 +310,7 @@ class Solution {
|
||||
}
|
||||
```
|
||||
|
||||
## Python
|
||||
Python:
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
@ -312,7 +331,8 @@ class Solution:
|
||||
return s[left:right + 1]
|
||||
|
||||
```
|
||||
> 双指针法:
|
||||
双指针:
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def longestPalindrome(self, s: str) -> str:
|
||||
@ -340,13 +360,13 @@ class Solution:
|
||||
return s[start:end]
|
||||
|
||||
```
|
||||
## Go
|
||||
Go:
|
||||
|
||||
```go
|
||||
|
||||
```
|
||||
|
||||
## JavaScript
|
||||
JavaScript:
|
||||
|
||||
```js
|
||||
//动态规划解法
|
||||
@ -462,8 +482,9 @@ var longestPalindrome = function(s) {
|
||||
};
|
||||
```
|
||||
|
||||
## C
|
||||
动态规划:
|
||||
C:
|
||||
|
||||
动态规划:
|
||||
```c
|
||||
//初始化dp数组,全部初始为false
|
||||
bool **initDP(int strLen) {
|
||||
@ -513,7 +534,7 @@ char * longestPalindrome(char * s){
|
||||
}
|
||||
```
|
||||
|
||||
双指针:
|
||||
双指针:
|
||||
```c
|
||||
int left, maxLength;
|
||||
void extend(char *str, int i, int j, int size) {
|
||||
|
Reference in New Issue
Block a user