1. 程式人生 > >leetcode date2018/4/8

leetcode date2018/4/8

mage PQ AR char alt rev () img num

(1)

技術分享圖片

class Solution(object):
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        letters=abcdefghijklmnopqrstuvwxyz
        index=[s.index(l) for l in letters if s.count(l) == 1]
        return min(index) if len(index) > 0 else -1

(2)

技術分享圖片

# Definition for singly-linked list.
# class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def reverseList(self, head): """ :type head: ListNode :rtype: ListNode """ next=None while head: head.next,head,next
=next,head.next,head return next

(3)

技術分享圖片

class Solution(object):
    def intersect(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        c1 = collections.Counter(nums1)
        c2 = collections.Counter(nums2)
        
return list((c1&c2).elements())#elements返回一個叠代器。元素被重復了多少次,在該叠代器中就包含多少個該元素。元素排列無確定順序,個數小於1的元素不被包含。

leetcode date2018/4/8