码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode date2018/4/8

时间:2018-04-09 00:09:56      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:分享   bcd   tco   str   init   code   nbsp   int   etc   

(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

标签:分享   bcd   tco   str   init   code   nbsp   int   etc   

原文地址:https://www.cnblogs.com/proven/p/8748041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!