Class Solution
- java.lang.Object
-
- g0801_0900.s0825_friends_of_appropriate_ages.Solution
-
public class Solution extends Object
825 - Friends Of Appropriate Ages.Medium
There are
npersons on a social media website. You are given an integer arrayageswhereages[i]is the age of theithperson.A Person
xwill not send a friend request to a persony(x != y) if any of the following conditions is true:age[y] <= 0.5 * age[x] + 7age[y] > age[x]age[y] > 100 && age[x] < 100
Otherwise,
xwill send a friend request toy.Note that if
xsends a request toy,ywill not necessarily send a request tox. Also, a person will not send a friend request to themself.Return the total number of friend requests made.
Example 1:
Input: ages = [16,16]
Output: 2
Explanation: 2 people friend request each other.
Example 2:
Input: ages = [16,17,18]
Output: 2
Explanation: Friend requests are made 17 -> 16, 18 -> 17.
Example 3:
Input: ages = [20,30,100,110,120]
Output: 3
Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.
Constraints:
n == ages.length1 <= n <= 2 * 1041 <= ages[i] <= 120
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intnumFriendRequests(int[] ages)
-