3.26
跟妈妈进行了一波教育反思,拉钩了要好好互相对待的事,突然觉得啊虽然我妈老是打击式教育,但是也真的把我放在平等关系上了的。
3.27
好像又重新理解了那句话:“人生中最幸运的两件事,一件是时间终于将我对你的爱消耗殆尽,另一件是很久很久以前有一天我遇到你”
太难了这道题,终于有场外理我了,张哥yyds!被告知这是阿里一面里面最简单的题,那我不就寄了啊(体会到了差距,所以这段时间可能要认真卷了,不能三天打渔两天晒网卷了)
发现之前没有搞懂的迭代和递归最终还是要搞懂
变量要尽可能的缩小作用范围,如果能用局部的尽量用局部的,尽量不要用全局的,减少变量的作用域的范围。
迭代*2
在网上看到了一个大神的写法,但是感觉不太能理解
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
if not head:
return None
prev = None
cur = head
while cur:
cur.next, prev, cur = prev, cur, cur.next
return prev
cur.next, prev, cur = prev, cur, cur.next
这部分的运行方式,问了一下是同时进行的,如果想分开写就需要重新做个变量寄存cur.next如下
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
if not head:
return None
prev = None
cur = head
while cur:
t = cur.next
cur.next = prev
prev = cur
cur = t
return prev
递归:(别人的)
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
if not head or not head.next:
return head
else:
newhead = self.reverseList(head.next)
head.next.next = head
head.next = None
return newhead
这我是真的没太懂了明天问问吧