public class Solution
    {
        public int DominantIndex(int[] nums)
        {
            var list = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < nums.Length; i++)
            {
                list.Add(new KeyValuePair<int, int>(i, nums[i]));
            }

            var olist = list.OrderByDescending(x => x.Value).ToList();
            var basenum = olist[0].Value;
            for (int i = 1; i < olist.Count; i++)
            {
                if (basenum < olist[i].Value * 2)
                {
                    return -1;
                }
            }
            return olist[0].Key;
        }
    }

 

posted on 2018-10-01 11:58  Sempron2800+  阅读(87)  评论(0编辑  收藏  举报