这段时间比较忙,代码量都下降了,有点惭愧呐

 

LeetCode #56. 合并区间

断网了,没有提交。。

class Solution(object):
    def merge(self, intervals):
        """
        :type intervals: List[Interval]
        :rtype: List[Interval]
        """
        new_intervals = []
        i = 1
        while i<len(intervals):
            if intervals[i][0] <= intervals[i-1][1]:
                new_intervals.append([intervals[i-1][0],intervals[i][1]])
            else :
                new_intervals.append(intervals[i])
            i += 1
        return new_intervals

LeetCode 求众数

class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if nums == [] :
            return ''
        maxnum = 0
        count  = 0
        nums.sort()
        new_nums = set(nums)
        for i in new_nums:
            lenght = len(nums)
            while i in nums :
                nums.remove(i) 
                count += 1
            if count > maxnum:
                maxnum = count
                majornum = i
            count = 0
        return majornum