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

leetcode414

时间:2017-04-26 19:17:38      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:imu   int   amp   href   div   count   ber   des   list   

public class Solution {
    public int ThirdMax(int[] nums) {
        var third = 0;

            var list = nums.Distinct().OrderByDescending(x => x).ToList();
            if (list.Count == 0)
            {
                third = 0;
            }
            else if (list.Count >= 1 && list.Count <= 2)
            {
                third = list[0];
            }
            else
            {
                third = list[2];
            }
            return third;
    }
}

https://leetcode.com/problems/third-maximum-number/#/description

leetcode414

标签:imu   int   amp   href   div   count   ber   des   list   

原文地址:http://www.cnblogs.com/asenyang/p/6770026.html

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