#-*- coding: UTF-8 -*-
#l1 = ['1','3','2','3','2','1','1']
#l2 = sorted(sorted(set(l1),key=l1.index,reverse=False),reverse=True)
class Solution(object):
    def thirdMax(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if nums==[]:return []
        nums=sorted(sorted(set(nums),key=nums.index),reverse=True)
        if len(nums)>=3:
            return nums[2]
        else:return nums[0]

sol=Solution()
print sol.thirdMax([1, 2])

【leetcode❤python】 414. Third Maximum Number的更多相关文章

  1. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  2. 【leetcode】414. Third Maximum Number

    problem 414. Third Maximum Number solution 思路:用三个变量first, second, third来分别保存第一大.第二大和第三大的数,然后遍历数组. cl ...

  3. 【LeetCode】414. Third Maximum Number 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 替换最大值数组 使用set 三个变量 日期 题目地址 ...

  4. LeetCode Array Easy 414. Third Maximum Number

    Description Given a non-empty array of integers, return the third maximum number in this array. If i ...

  5. 【leetcode❤python】 374. Guess Number Higher or Lower

    #-*- coding: UTF-8 -*-# The guess API is already defined for you.# @param num, your guess# @return - ...

  6. 【leetcode❤python】 9. Palindrome Number

    #回文数#Method1:将整数转置和原数比较,一样就是回文数:负数不是回文数#这里反转整数时不需要考虑溢出,但不代表如果是C/C++等语言也不需要考虑class Solution(object):  ...

  7. 【leetcode❤python】 Maximum Depth of Binary Tree

    #-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):#     def __init ...

  8. 【leetcode❤python】Convert a Number to Hexadecimal

    #-*- coding: UTF-8 -*- class Solution(object):    hexDic={0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6', ...

  9. 【leetcode❤python】263. Ugly Number

    class Solution(object):    def isUgly(self, num):        if num<=0:return False        comlist=[2 ...

随机推荐

  1. ngrok访问外网

    1. 外网映射工具介绍 windows用户: 1,下载windows版本的客户端,解压到你喜欢的目录2,在命令行下进入到path/to/windows_386/下3,执行 ngrok -config= ...

  2. spring-session整合

    如果项目之前没有整合过spring-data-redis的话,这一步需要先做,在maven中添加这两个依赖: <dependency>     <groupId>org.spr ...

  3. Json的语法及使用方法

    Json的语法及使用方法 Json(JavaScript Object Notation)对象表示标识,是一种轻量级的数据交换语言,比XML更容易解析,独立于语言和平台. 语法规则: 对象用{}保存 ...

  4. 转载自~浮云比翼:Step by Step:Linux C多线程编程入门(基本API及多线程的同步与互斥)

    Step by Step:Linux C多线程编程入门(基本API及多线程的同步与互斥)   介绍:什么是线程,线程的优点是什么 线程在Unix系统下,通常被称为轻量级的进程,线程虽然不是进程,但却可 ...

  5. Thinking in Java——笔记(10)

    Inner Classes It allows you to group classes that logically belong together and to control the visib ...

  6. 基于VirtualBox的多重载入

    问题描述 这个问题要追溯到中秋之前,也就是写第一周博客的时候,当时我用的还是虚拟机上的ubuntu:当时我的ubuntu不是最新版,所以有提示升级,你懂的,我升了(因为时间有点久,我先去吃了个饭):等 ...

  7. Selenium脚本编写环境的搭建/XPath

    编写环境主要分为三个部分: JUnit : java单元测试框架: Firebug: firefox 附加组件,Firebug是firefox下的一个扩展,能够调试所有网站语言,如Html,Css等, ...

  8. IIS删除http header信息如Server, X-Powered-By, 和X-AspNet-Version

    响应头信息原始头信息 Cache-Control private Content-Length 78457 Content-Type text/html; charset=utf-8 Date Fri ...

  9. AngularJs转换json日期/Date(00000)/

    //过滤器ngApp.filter('jsonDate', function ($filter) { return function (input, format) { var timestamp = ...

  10. iOS小技巧3

    将颜色合成图片 将颜色合成图片 +(UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1 ...