Skip to content

Commit 2acc33f

Browse files
authored
Merge pull request yychuyu#794 from MyJavaRoad/master
youransuifeng
2 parents f90bac5 + e5cb820 commit 2acc33f

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int[] twoSum(int[] nums, int target) {
3+
HashMap<Integer , Integer> map = new HashMap<>();
4+
for(int i = 0; i < nums.length; i++){
5+
if(map.containsKey(nums[i])){
6+
return new int[]{map.get(nums[i]),i};
7+
}else{
8+
map.put(target-nums[i],i);
9+
}
10+
}
11+
return null;
12+
13+
}
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode(int x) { val = x; }
7+
* }
8+
*/
9+
class Solution {
10+
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
11+
if(l1 == null && l2 == null){
12+
return null;
13+
}else if(l1 == null || l2 == null){
14+
return l1 != null ? l1:l2;
15+
}else{
16+
ListNode l3;
17+
if(l1.val + l2.val < 10){
18+
l3 = new ListNode(l1.val + l2.val);
19+
l3.next = addTwoNumbers(l1.next , l2.next);
20+
}else{
21+
l3 = new ListNode(l1.val + l2.val - 10);
22+
l3.next = addTwoNumbers(addTwoNumbers(l1.next , new ListNode(1)) , l2.next);
23+
}
24+
return l3;
25+
}
26+
27+
28+
29+
}
30+
}

submittors/悠然随风.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe6d4836e9f2a4497e56748227112d155f025778

0 commit comments

Comments
 (0)