- Intersection of Two Linked Lists
**思路:没有读懂题目的含义,找到两个单链表的交点,那么相交以后是一样的结点数吗?相交以后能有岔开吗?直接抄袭的网上的,都做到快第20天了,我还是不会独立解题,尤其是链表类的。
class Solution(object):
def getIntersectionNode(self, headA, headB):
"""
:type head1, head1: ListNode
:rtype: ListNode
"""
if not headA or not headB:
return None
else:
p = {}
i = headA
while i:
p[i.val] = 1
i = i.next
i = headB
while i :
if i.val in p:
return i
else:
i = i.next
return None
-
Excel Sheet Column Title
**思路:这个和昨天的字母串转数字是一个互逆的题。将十进制数转26进制。这里需要弄清楚的一点,字符串的初始化,不是[],二是‘’。
class Solution(object):
def convertToTitle(self, n):
"""
:type n: int
:rtype: str
"""
ss = ''
sum1 = n
while sum1:
[sum1,a] = divmod(sum1-1,26)
ss = chr(a + 65) + ss
return ss
网友评论