1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-10-18 14:52:09 +02:00
LeetCode/cs/divide-players-into-teams-of-equal-skill.cs
2024-10-04 21:18:47 +02:00

18 lines
450 B
C#

public class Solution {
public long DividePlayers(int[] skill) {
Array.Sort(skill);
var expectedSkill = skill[0] + skill[skill.Length - 1];
long chemistry = 0;
for (int i = 0, j = skill.Length - 1; i < j; ++i, --j) {
if (skill[i] + skill[j] != expectedSkill) {
return -1;
}
chemistry += skill[i] * (long)skill[j];
}
return chemistry;
}
}