验证,校对

pull/33/head
jaredliw 2021-07-16 00:06:52 +08:00
parent 4a8c81e88e
commit 88fcd88712
14 changed files with 180 additions and 197 deletions

View File

@ -1,5 +1,3 @@
> **[tan45du_one](https://raw.githubusercontent.com/tan45du/tan45du.github.io/master/个人微信.15egrcgqd94w.jpg)** ,备注 github + 题目 + 问题 向我反馈
>
>
@ -63,7 +61,6 @@ class Solution {
return true;
}
}
```
C++ Code:
@ -72,18 +69,23 @@ C++ Code:
class Solution {
public:
bool isPalindrome(ListNode* head) {
//这里需要用动态数组,因为我们不知道链表的长度
vector<int> arr;
ListNode* copynode = head;
//将链表的值复制到数组中
while (copynode) {
arr.push_back(copynode->val);
copynode = copynode->next;
}
//双指针遍历数组
int back = 0;
int pro = arr.size() - 1;
while (back < pro) {
//判断两个指针的值是否相等
if (arr[back] != arr[pro]) {
return false;
}
//移动指针
back++;
pro--;
}
@ -121,7 +123,7 @@ var isPalindrome = function(head) {
Python Code:
```py
```python
class Solution:
def isPalindrome(self, head: ListNode) -> bool:
arr = []
@ -145,7 +147,7 @@ class Solution:
****
@ -165,17 +167,17 @@ class Solution {
}
//找到中间节点,也就是翻转的头节点,这个在昨天的题目中讲到
//但是今天和昨天有一些不一样的地方就是,如果有两个中间节点返回第一个,昨天的题目是第二个
ListNode midenode = searchmidnode(head);
ListNode midnode = searchmidnode(head);
//原地翻转链表,需要两个辅助指针。这个也是面试题目,大家可以做一下
//这里我们用的是midnode.next需要注意因为我们找到的是中点但是我们翻转的是后半部分
ListNode backhalf = reverse(midenode.next);
ListNode backhalf = reverse(midnode.next);
//遍历两部分链表,判断值是否相等
ListNode p1 = head;
ListNode p2 = backhalf;
while (p2 != null) {
if (p1.val != p2.val) {
//若要还原记得这里也要reverse
midenode.next = reverse(backhalf);
midnode.next = reverse(backhalf);
return false;
}
p1 = p1.next;
@ -183,7 +185,7 @@ class Solution {
}
//还原链表并返回结果,这一步是需要注意的,我们不可以破坏初始结构,我们只是判断是否为回文,
//当然如果没有这一步也是可以AC但是面试的时候题目要求可能会有这一条。
midenode.next = reverse(backhalf);
midnode.next = reverse(backhalf);
return true;
}
//找到中点
@ -222,17 +224,17 @@ public:
}
//找到中间节点,也就是翻转的头节点,这个在昨天的题目中讲到
//但是今天和昨天有一些不一样的地方就是,如果有两个中间节点返回第一个,昨天的题目是第二个
ListNode * midenode = searchmidnode(head);
ListNode * midnode = searchmidnode(head);
//原地翻转链表,需要两个辅助指针。这个也是面试题目,大家可以做一下
//这里我们用的是midnode->next需要注意因为我们找到的是中点但是我们翻转的是后半部分
ListNode * backhalf = reverse(midenode->next);
ListNode * backhalf = reverse(midnode->next);
//遍历两部分链表,判断值是否相等
ListNode * p1 = head;
ListNode * p2 = backhalf;
while (p2 != nullptr) {
if (p1->val != p2->val) {
//若要还原记得这里也要reverse
midenode.next = reverse(backhalf);
midnode->next = reverse(backhalf);
return false;
}
p1 = p1->next;
@ -240,7 +242,7 @@ public:
}
//还原链表并返回结果,这一步是需要注意的,我们不可以破坏初始结构,我们只是判断是否为回文,
//当然如果没有这一步也是可以AC但是面试的时候题目要求可能会有这一条。
midenode->next = reverse(backhalf);
midnode->next = reverse(backhalf);
return true;
}
//找到中间的部分
@ -277,17 +279,17 @@ var isPalindrome = function(head) {
}
//找到中间节点,也就是翻转的头节点,这个在昨天的题目中讲到
//但是今天和昨天有一些不一样的地方就是,如果有两个中间节点返回第一个,昨天的题目是第二个
let midenode = searchmidnode(head);
let midnode = searchmidnode(head);
//原地翻转链表,需要两个辅助指针。这个也是面试题目,大家可以做一下
//这里我们用的是midnode.next需要注意因为我们找到的是中点但是我们翻转的是后半部分
let backhalf = reverse(midenode.next);
let backhalf = reverse(midnode.next);
//遍历两部分链表,判断值是否相等
let p1 = head;
let p2 = backhalf;
while (p2 != null) {
if (p1.val != p2.val) {
//若要还原记得这里也要reverse
midenode.next = reverse(backhalf);
midnode.next = reverse(backhalf);
return false;
}
p1 = p1.next;
@ -295,7 +297,7 @@ var isPalindrome = function(head) {
}
//还原链表并返回结果,这一步是需要注意的,我们不可以破坏初始结构,我们只是判断是否为回文,
//当然如果没有这一步也是可以AC但是面试的时候题目要求可能会有这一条。
midenode.next = reverse(backhalf);
midnode.next = reverse(backhalf);
return true;
};
@ -326,7 +328,7 @@ var reverse = function(slow) {
Python Code:
```py
```python
class Solution:
def isPalindrome(self, head: ListNode) -> bool:
if head is None or head.next is None:
@ -344,12 +346,11 @@ class Solution:
if p1.val != p2.val:
# reverse
midnode.next = self.reverse(backhalf)
print(head)
return False
p1 = p1.next
p2 = p2.next
#
AC
# AC
midnode.next = self.reverse(backhalf)
return True

View File

@ -12,7 +12,7 @@
> pos-1
>
> true false
> true false
1
@ -56,22 +56,6 @@ public class Solution {
}
```
JS Code:
```javascript
var hasCycle = function(head) {
let fast = head;
let slow = head;
while (fast && fast.next) {
fast = fast.next.next;
slow = slow.next;
if (fast === slow) {
return true;
}
}
return false;
};
```
C++ Code:
```cpp
@ -92,17 +76,34 @@ public:
};
```
JS Code:
```javascript
var hasCycle = function(head) {
let fast = head;
let slow = head;
while (fast && fast.next) {
fast = fast.next.next;
slow = slow.next;
if (fast === slow) {
return true;
}
}
return false;
};
```
Python Code:
```py
```python
class Solution:
def hasCycle(self, head: ListNode) -> bool:
fast = head
slow = head
while fast and fast.next:
fast = fast.next.next
low = low.next
if fast == low:
slow = slow.next
if fast == slow:
return True
return False
```

View File

@ -18,35 +18,7 @@
```java
public class Solution {
public boolean hasCycle(ListNode head) {
//特殊情况,无节点或只有一个节点的情况
if(head == null || head.next == null){
return false;
}
//设置快慢指针
ListNode pro = head.next;
ListNode last = head;
//循环条件
while( pro != null && pro.next!=null){
pro=pro.next.next;
last=last.next;
//两指针相遇
if(pro == last){
return true;
}
}
//循环结束,指针没有相遇,说明没有环。相当于快指针遍历了一遍链表
return false;
}
}
```
[](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E9%93%BE%E8%A1%A8%E7%AF%87/leetcode141%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8.md)。
[leetcode 141 ](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E9%93%BE%E8%A1%A8%E7%AF%87/leetcode141%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8.md)。
绿
@ -100,11 +72,15 @@ public:
ListNode *detectCycle(ListNode *head) {
if (head == nullptr) return head;
if (head->next == nullptr) return head->next;
//创建新的HashSet用于保存节点
set<ListNode *> hash;
//遍历链表
while (head != nullptr) {
//判断哈希表中是否含有某节点,没有则保存,含有则返回该节点
if (hash.count(head)) {
return head;
}
//不含有,则进行保存,并移动指针
hash.insert(head);
head = head->next;
}
@ -137,7 +113,7 @@ var detectCycle = function(head) {
Python Code:
```py
```python
class Solution:
def detectCycle(self, head: ListNode) -> ListNode:
if head is None:
@ -253,17 +229,22 @@ JS Code:
```js
var detectCycle = function(head) {
//快慢指针
let fast = head;
let slow = head;
//设置循环条件
while (fast && fast.next) {
fast = fast.next.next;
slow = slow.next;
//相遇
if (fast == slow) {
let newptr = head;
//设置一个新的指针从头节点出发慢指针速度为1所以可以使用慢指针从相遇点出发
while (newptr != slow) {
slow = slow.next;
newptr = newptr.next;
}
//在环入口相遇
return slow;
}
}
@ -273,7 +254,7 @@ var detectCycle = function(head) {
Python Code:
```py
```python
class Solution:
def detectCycle(self, head: ListNode) -> ListNode:
#

View File

@ -8,7 +8,7 @@
[](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/%E5%85%B3%E4%BA%8E%E9%93%BE%E8%A1%A8%E7%9A%84%E9%82%A3%E4%BA%9B%E4%BA%8B.md)
[](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/%E7%9B%B4%E6%8E%A5%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA%8F.md)和[【动画模拟】归并排序](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/%E5%BD%92%E5%B9%B6%E6%8E%92%E5%BA%8F.md)思想的话,可以先复习一下,不然这两道题目会看云里雾里。
[](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/%E7%9B%B4%E6%8E%A5%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA%8F.md)和[【动画模拟】归并排序](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E7%AE%97%E6%B3%95/%E5%BD%92%E5%B9%B6%E6%8E%92%E5%BA%8F.md)思想的话,可以先复习一下,不然这两道题目会看云里雾里。
#### [147. ](https://leetcode-cn.com/problems/insertion-sort-list/)
@ -30,7 +30,7 @@
On,
O(n)
@ -68,7 +68,7 @@
3 2 4 243
4
4
![](https://cdn.jsdelivr.net/gh/tan45du/photobed@master/44444444.29mvcvs4yrms.png)
@ -143,9 +143,9 @@ public:
continue;
}
//开始出发,查找新元素的合适位置
temphead = dummyNode;
ListNode * temphead = dummyNode;
while (temphead->next->val <= pre->val) {
ListNode * temphead = temphead->next;
temphead = temphead->next;
}
//此时我们已经找到了合适位置,我们需要进行插入,大家可以画一画
last->next = pre->next;
@ -195,7 +195,7 @@ var insertionSortList = function(head) {
Python Code:
```py
```python
class Solution:
def insertionSortList(self, head: ListNode) -> ListNode:
if head is None or head.next is None:

View File

@ -1,6 +1,12 @@
> **[tan45du_one](https://raw.githubusercontent.com/tan45du/tan45du.github.io/master/个人微信.15egrcgqd94w.jpg)** ,备注 github + 题目 + 问题 向我反馈
>
>
>
> <u>[****](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u> 两个平台同步,想要和题友一起刷题,互相监督的同学,可以在我的小屋点击<u>[**刷题小队**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u>进入。
#### [206. ](https://leetcode-cn.com/problems/reverse-linked-list/)
@ -19,9 +25,9 @@
low pro head
pro
temp pro
pro pro = pro.next.
pro pro = pro.next
temp low
@ -59,29 +65,6 @@ class Solution {
}
}
```
JS Code:
```javascript
var reverseList = function(head) {
//特殊情况
if(!head || !head.next) {
return head;
}
let low = null;
let pro = head;
while (pro) {
//代表橙色指针
let temp = pro;
//移动绿色指针
pro = pro.next;
//反转节点
temp.next = low;
//移动黄色指针
low = temp;
}
return low;
};
```
C++ Code:
```cpp
@ -109,12 +92,36 @@ public:
};
```
JS Code:
```javascript
var reverseList = function(head) {
//特殊情况
if(!head || !head.next) {
return head;
}
let low = null;
let pro = head;
while (pro) {
//代表橙色指针
let temp = pro;
//移动绿色指针
pro = pro.next;
//反转节点
temp.next = low;
//移动黄色指针
low = temp;
}
return low;
};
```
Python Code:
```py
```python
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
//特殊情况
#
if head is None or head.next is None:
return head
low = None
@ -147,8 +154,8 @@ class Solution {
}
//保存最后一个节点
ListNode pro = reverseList(head.next);
//将节点进行反转。我们可以这样理解 4.next.next = 4;
//4.next = 5
//将节点进行反转。我们可以这样理解 4.next.next = 4
//4.next = 5
//则 5.next = 4 则实现了反转
head.next.next = head;
//防止循环
@ -156,29 +163,9 @@ class Solution {
return pro;
}
}
```
JS Code:
```javascript
var reverseList = function(head) {
//结束条件
if (!head || !head.next) {
return head;
}
//保存最后一个节点
let pro = reverseList(head.next);
//将节点进行反转。我们可以这样理解 4.next.next = 4;
//4.next = 5
//则 5.next = 4 则实现了反转
head.next.next = head;
//防止循环
head.next = null;
return pro;
};
```
C++:
C++ Code:
```cpp
class Solution {
@ -190,8 +177,8 @@ public:
}
//保存最后一个节点
ListNode * pro = reverseList(head->next);
//将节点进行反转。我们可以这样理解 4->next->next = 4;
//4->next = 5
//将节点进行反转。我们可以这样理解 4->next->next = 4
//4->next = 5
//则 5->next = 4 则实现了反转
head->next->next = head;
//防止循环
@ -201,9 +188,29 @@ public:
};
```
JS Code:
```javascript
var reverseList = function(head) {
//结束条件
if (!head || !head.next) {
return head;
}
//保存最后一个节点
let pro = reverseList(head.next);
//将节点进行反转。我们可以这样理解 4.next.next = 4
//4.next = 5
//则 5.next = 4 则实现了反转
head.next.next = head;
//防止循环
head.next = null;
return pro;
};
```
Python Code:
```py
```python
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
#
@ -211,8 +218,8 @@ class Solution:
return head
#
pro = self.reverseList(head.next)
# 4->next->next = 4;
# 4->next = 5
# 4->next->next = 4
# 4->next = 5
# 5->next = 4
head.next.next = head
#
@ -224,18 +231,18 @@ class Solution:
> [@jaredliw](https://github.com/jaredliw)注:
>
>
>
>
> ```py
> ```python
> class Solution:
> def reverseList(self, head: ListNode, prev_nd: ListNode = None) -> ListNode:
> #
> if head is None:
> return prev_nd
> #
> next_nd = head.next
> head.next = prev_nd
> #
> return self.reverseList(next_nd, head)
> def reverseList(self, head: ListNode, prev_nd: ListNode = None) -> ListNode:
> #
> if head is None:
> return prev_nd
> #
> next_nd = head.next
> head.next = prev_nd
> #
> return self.reverseList(next_nd, head)
> ```

View File

@ -26,7 +26,7 @@
####
@ -109,7 +109,7 @@ var oddEvenList = function(head) {
Python Code:
```py
```python
class Solution:
def oddEvenList(self, head: ListNode) -> ListNode:
if head is None or head.next is None:

View File

@ -48,9 +48,9 @@ class Solution {
public ListNode deleteDuplicates(ListNode head) {
//侦察兵指针
ListNode pre = head;
//创建虚拟头节点接上head
//创建节点接上head
ListNode dummy = new ListNode(-1);
dummy.next = pre;
dummy.next = head;
//跟随的指针
ListNode low = dummy;
while(pre != null && pre.next != null) {
@ -82,9 +82,9 @@ public:
ListNode* deleteDuplicates(ListNode* head) {
//侦察兵指针
ListNode * pre = head;
//创建虚拟头节点接上head
ListNode * dummy = new ListNode(-1 head);
dummy->next = pre;
//创建节点接上head
ListNode * dummy = new ListNode(-1);
dummy->next = head;
//跟随的指针
ListNode * low = dummy;
while(pre != nullptr && pre->next != nullptr) {
@ -141,7 +141,7 @@ var deleteDuplicates = function(head) {
Python Code:
```py
```python
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
#
@ -162,6 +162,6 @@ class Solution:
else:
pre = pre.next
low = low.next
return low.next # headhead
return dummy.next # headhead
```

View File

@ -131,12 +131,7 @@ var partition = function(head, x) {
Python Code:
```py
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
```python
class Solution:
def partition(self, head: ListNode, x: int) -> ListNode:
pro = head
@ -161,3 +156,4 @@ class Solution:
small.next = headbig.next
return headsmall.next
```

View File

@ -4,14 +4,12 @@
>
> <u>[****](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u> 两个平台同步,想要和题友一起刷题,互相监督的同学,可以在我的小屋点击<u>[**刷题小队**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u>进入。
2 1 1 [leetcode 206 ](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E9%93%BE%E8%A1%A8%E7%AF%87/leetcode206%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md)
2 1 1 [leetcode 206 ](https://github.com/chefyuan/algorithm-base/blob/main/animation-simulation/%E9%93%BE%E8%A1%A8%E7%AF%87/leetcode206%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md)
#### [92. II](https://leetcode-cn.com/problems/reverse-linked-list-ii/)
836
`head` `left` `right` `left <= right` `left` `right` ****
** 1**
@ -166,7 +164,6 @@ var reverseBetween = function(head, left, right) {
return temp.next;
};
//和反转链表1代码一致
var reverse = function(head) {
let low = null;
@ -183,7 +180,7 @@ var reverse = function(head) {
Python Code:
```py
```python
class Solution:
def reverseBetween(self, head: ListNode, left: int, right: int) -> ListNode:
#

View File

@ -6,7 +6,7 @@
#### [ Offer 25. ](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/)
****
@ -19,7 +19,7 @@
headpreheadpre.next
headpre headpre.next
@ -105,7 +105,7 @@ var mergeTwoLists = function(l1, l2) {
Python Code:
```py
```python
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
headpro = ListNode(-1)

View File

@ -115,7 +115,7 @@ var getIntersectionNode = function(headA, headB) {
Python Code:
```py
```python
class Solution:
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
tempa = headA
@ -207,7 +207,7 @@ var getIntersectionNode = function(headA, headB) {
Python Code:
```py
```python
class Solution:
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
#

View File

@ -12,13 +12,13 @@
n
1038K
1038k

View File

@ -6,7 +6,7 @@
#### [876. ](https://leetcode-cn.com/problems/middle-of-the-linked-list/)
head
head
@ -17,7 +17,7 @@
3
```
>
>
** 2**
@ -26,9 +26,9 @@
4
```
>
>
##
****
@ -44,7 +44,7 @@
slow
slow
![](https://img-blog.csdnimg.cn/20210321131249789.gif)
@ -105,7 +105,7 @@ var middleNode = function(head) {
Python Code:
```py
```python
class Solution:
def middleNode(self, head: ListNode) -> ListNode:
fast = head #

View File

@ -23,22 +23,22 @@
1
```java
(7 -> 1 -> 6) + (5 -> 9 -> 2)617 + 295
2 -> 1 -> 9912
(7 -> 1 -> 6) + (5 -> 9 -> 2) 617 + 295
2 -> 1 -> 9 912
```
2
```java
(9 -> 9) + (9 -> 9),99+99
8->9->1
(9 -> 9) + (9 -> 9) 99 + 99
8 -> 9 -> 1
```
3
```java
(5)+(5),5+5
0->1
(5) + (5) 5 + 5
0 -> 1
```
****
@ -67,7 +67,7 @@
![](https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/链表求和.1yh4ymdee3k0.gif)
nlist1summod1
nlist 1summod 1
@ -79,7 +79,7 @@ Java Code:
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
//待会儿要返回的链表
ListNode nList = new ListNode(-1);//虚拟头节点
ListNode nList = new ListNode(-1);//节点
ListNode tempnode = nList;
//用来保存进位值初始化为0
int summod = 0;
@ -92,7 +92,7 @@ class Solution {
int sum = l1num+l2num+summod;
//更新进位值例18/10=19/10=0
summod = sum/10;
//新节点保存的值18% 8=2则添加2
//新节点保存的值18%8=2则添加2
sum = sum%10;
//添加节点
tempnode.next = new ListNode(sum);
@ -109,7 +109,7 @@ class Solution {
if (summod != 0) {
tempnode.next = new ListNode(summod);
}
return nList.next;//去除-1节点
return nList.next;//去除节点
}
}
```
@ -121,7 +121,7 @@ class Solution {
public:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
//待会儿要返回的链表
ListNode * nList = new ListNode(-1);//虚拟头节点
ListNode * nList = new ListNode(-1);//节点
ListNode * tempnode = nList;
//用来保存进位值初始化为0
int summod = 0;
@ -134,7 +134,7 @@ public:
int sum = l1num + l2num + summod;
//更新进位值例18/10=19/10=0
summod = sum / 10;
//新节点保存的值1 %8=2则添加2
//新节点保存的值18%8=2则添加2
sum = sum % 10;
//添加节点
tempnode->next = new ListNode(sum);
@ -151,7 +151,7 @@ public:
if (summod != 0) {
tempnode->next = new ListNode(summod);
}
return nList->next;//去除-1节点
return nList->next;//节点
}
};
```
@ -161,7 +161,7 @@ JS Code:
```js
var addTwoNumbers = function(l1, l2) {
//待会儿要返回的链表
let nList = new ListNode(-1);//虚拟头节点
let nList = new ListNode(-1);//节点
let tempnode = nList;
//用来保存进位值初始化为0
let summod = 0;
@ -174,7 +174,7 @@ var addTwoNumbers = function(l1, l2) {
let sum = l1num + l2num + summod;
//更新进位值例18/10=19/10=0
summod = ~~(sum / 10);
//新节点保存的值1 %8=2则添加2
//新节点保存的值18%8=2则添加2
sum = sum % 10;
//添加节点
tempnode.next = new ListNode(sum);
@ -191,21 +191,21 @@ var addTwoNumbers = function(l1, l2) {
if (summod !== 0) {
tempnode.next = new ListNode(summod);
}
return nList.next;//去除-1节点
return nList.next;//去除节点
};
```
Python Code:
```py
```python
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
#
nList = ListNode(-1) #
nList = ListNode(-1) #
tempnode = nList
# 0
summod = 0
while l1 is not None and l2 is not None:
while l1 is not None o l2 is not None:
# l1l1num0
# 0
l1num = 0 if l1 is None else l1.val
@ -227,6 +227,6 @@ class Solution:
#
if summod != 0:
tempnode.next = ListNode(summod)
return nList.next # -1
return nList.next #
```