【python3】leetcode 414. Third Maximum Numberr (easy)
414. Third Maximum Numberr (easy)
一、
返回第三大的數字,第一想法就是要排序
用了一個magic method
class Solution: def thirdMax(self, nums): """ :type nums: List[int] :rtype: int """ nums = list(set(nums)) if(len(nums) < 3):return max(nums) return sorted(nums).__getitem__(-3)
Runtime: 72 ms, faster than 8.82% of Python3
相關推薦
【python3】leetcode 414. Third Maximum Numberr (easy)
414. Third Maximum Numberr (easy) 一、 返回第三大的數字,第一想法就是要排序 用了一個magic method class Solution: def thirdMax(self, nums): "
【python3】leetcode 888. Fair Candy Swap(easy)
888. Fair Candy Swap(easy) ALice要給bob一堆糖果,bob要給alice一堆,最後兩人糖果總數要相同,假設alice給的那堆有a個,bob給的那堆有b個 解方程吧~~ sum(A)-a+b = sum(b) - b + a  
【python3】leetcode 724. Find Pivot Index (easy)
724. Find Pivot Index (easy) Given an array of integers nums, write a method that returns the "pivot" index of this array. We define t
【python3】leetcode 88. Merge Sorted Array (easy)
88. Merge Sorted Array (easy) Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 
【python3】leetcode 566. Reshape the Matrix(easy)
566. Reshape the Matrix(easy) In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one wit
【python3】leetcode 941. Valid Mountain Array(easy)
941. Valid Mountain Array(easy) Given an array A of integers, return true if and only if it is a valid mountain
【python3】leetcode 832. Flipping an Image(easy)
832. Flipping an Image(easy) Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulti
【python3】leetcode 485. Max Consecutive Onesr (easy)
485. Max Consecutive Onesr (easy) Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,
【python3】leetcode 561. Array Partition I (easy)
561. Array Partition I (easy) Given an array of 2n integers, your task is to group these integers into n pairs of integer,
【python3】leetcode 605. Can Place Flowers(easy)
605. Can Place Flowers(easy) Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers canno
【python3】leetcode 748. Shortest Completing Word(easy)
748. Shortest Completing Word(easy) Find the minimum length word from a given dictionary words, which has all the letters from the string
【python3】leetcode 594. Longest Harmonious Subsequence(easy)
594. Longest Harmonious Subsequence(easy) We define a harmonious array is an array where the difference between its maximum value and its mini
【python3】leetcode 206. Reverse Linked List (easy)
206. Reverse Linked List (easy) Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3-&
【python3】leetcode 141. Linked List Cycle (easy)
141. Linked List Cycle (easy) Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list,
【python3】leetcode 817. Linked List Components (Medium)
817. Linked List Components (Medium) We are given head, the head node of a linked list containing unique integer values.
【python3】leetcode 203. Remove Linked List Elements (easy)
203. Remove Linked List Elements (easy) Remove all elements from a linked list of integers that have value val. Example: Input: 1-
【c/c++】leetcode 35. Search Insert Position(easy)
35. Search Insert Position(easy) Given a sorted array and a target value, return the index if the target is found. If not, return the in
【python3】leetcode 628. Maximum Product of Three Numbers(easy)
628. Maximum Product of Three Numbers(easy) Given an integer array, find three numbers whose product is maximum and output the maximum product
leetcode-414-Third Maximum Number
long 重復元素 HERE maximum 文件 如何 ssi 以及 tin 題目描述: Given a non-empty array of integers, return the third maximum number in this array. If it d
【演算法】LeetCode演算法題-Maximum Subarray
這是悅樂書的第154次更新,第156篇原創 01 看題和準備 今天介紹的是LeetCode演算法題中Easy級別的第13題(順位題號是53)。給定一個整數陣列nums,找出一個最大和,此和是由陣列中索引連續的元素組成,至少包含一個元素。例如: 輸入:[-2, 1, -