首页 > 代码库 > leetcode414

leetcode414

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