-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution825.cs
40 lines (35 loc) · 936 Bytes
/
Solution825.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
34
35
36
37
38
39
40
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution825
{
/// <summary>
/// 825. Friends Of Appropriate Ages - Medium
/// <a href="https://leetcode.com/problems/friends-of-appropriate-ages">See the problem</a>
/// </summary>
public int NumFriendRequests(int[] ages)
{
var count = new int[121];
foreach (var age in ages)
{
count[age]++;
}
var result = 0;
for (var i = 1; i <= 120; i++)
{
for (var j = 1; j <= 120; j++)
{
if (j <= 0.5 * i + 7 || j > i || (j > 100 && i < 100))
{
continue;
}
result += count[i] * count[j];
if (i == j)
{
result -= count[i];
}
}
}
return result;
}
}