File tree Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -260,7 +260,26 @@ public:
260260
261261# 其他语言版本
262262
263- ## Java
263+ Java:
264+
265+ ``` java
266+ public int [] twoSum(int [] nums, int target) {
267+ int [] res = new int [2 ];
268+ if (nums == null || nums. length == 0 ){
269+ return res;
270+ }
271+ Map<Integer , Integer > map = new HashMap<> ();
272+ for (int i = 0 ; i < nums. length; i++ ){
273+ int temp = target - nums[i];
274+ if (map. containsKey(temp)){
275+ res[1 ] = i;
276+ res[0 ] = map. get(temp);
277+ }
278+ map. put(nums[i], i);
279+ }
280+ return res;
281+ }
282+ ```
264283
265284``` java
266285// 双指针 中心扩散法
@@ -291,7 +310,7 @@ class Solution {
291310}
292311```
293312
294- ## Python
313+ Python:
295314
296315``` python
297316class Solution :
@@ -312,7 +331,8 @@ class Solution:
312331 return s[left:right + 1 ]
313332
314333```
315- > 双指针法:
334+ 双指针:
335+
316336``` python
317337class Solution :
318338 def longestPalindrome (self , s : str ) -> str :
@@ -340,13 +360,13 @@ class Solution:
340360 return s[start:end]
341361
342362```
343- ## Go
363+ Go:
344364
345365``` go
346366
347367```
348368
349- ## JavaScript
369+ JavaScript:
350370
351371``` js
352372// 动态规划解法
@@ -462,8 +482,9 @@ var longestPalindrome = function(s) {
462482};
463483```
464484
465- ## C
466- 动态规划:
485+ C:
486+
487+ 动态规划:
467488``` c
468489// 初始化dp数组,全部初始为false
469490bool **initDP (int strLen) {
@@ -513,7 +534,7 @@ char * longestPalindrome(char * s){
513534}
514535```
515536
516- 双指针:
537+ 双指针:
517538```c
518539int left, maxLength;
519540void extend(char *str, int i, int j, int size) {
You can’t perform that action at this time.
0 commit comments