forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1086-HighFive.cs
33 lines (28 loc) · 974 Bytes
/
1086-HighFive.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//-----------------------------------------------------------------------------
// Runtime: 236ms
// Memory Usage: 33.3 MB
// Link: https://leetcode.com/submissions/detail/327393922/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
namespace LeetCode
{
public class _1086_HighFive
{
public int[][] HighFive(int[][] items)
{
var map = new Dictionary<int, List<int>>();
foreach (var item in items)
{
if (!map.ContainsKey(item[0]))
map.Add(item[0], new List<int>());
map[item[0]].Add(item[1]);
}
var result = new int[map.Keys.Count][];
var i = 0;
foreach (var pair in map)
result[i++] = new int[] { pair.Key, pair.Value.OrderByDescending(a => a).Take(5).Sum() / 5 };
return result;
}
}
}