Day19

作者: wendy_要努力努力再努力 | 来源:发表于2017-11-18 10:32 被阅读0次
    1. 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
    

    1. 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
    

    相关文章

      网友评论

          本文标题:Day19

          本文链接:https://www.haomeiwen.com/subject/npfevxtx.html