825. Friends Of Appropriate Ages
握手定理
年齡為i的人,和年齡為j的人,最終可配對r(i)Xr(j),同齡人之間可配對數為r(i)X(r(i)-1)
class Solution {
public:
/*
小於等於14,是不可以滴,所以直接從15開始取值
*/
int numFriendRequests(vector<int>& ages) {
vector<int> ren(121,0);
for(auto age:ages) ren[age]++;
int result = 0;
for(int i =15,minage=15,sumage=0;i<121;sumage+=ren[i],result+=ren[i++]*(sumage-1))
while(minage<=0.5*i+7) sumage -=ren[minage++];
return result;
}
};
相關文章
- [LeetCode] 825. Friends Of Appropriate AgesLeetCodeAPP
- Recommend Friends
- No appropriate protocolAPPProtocol
- D - New Friends
- man -k : nothing appropriate.APP
- ORA-12519 TNS:no appropriate service handler foundAPP
- mORMot and Open Source friends SynProject Tutorial (SynProject教程)ORMProject
- 備份時報no channel allocated for maintenance(of an appropriate type)AINaNAPP
- King是如何打造三消新秀《Candy Crush Friends Saga》?
- Oracle案例03——RMAN-06091: no channel allocated for maintenance (of an appropriate type)OracleAINaNAPP
- 黑客竊取了超過 2 億個 Zynga“Words with Friends”玩家資料黑客
- Ubuntu 更換新 Logo :橙色+矩形 Logo|“Circle of Friends”主題更緊湊更統一UbuntuGo
- 記一次部署在docker環境專案傳送郵件出現No appropriate protocolDockerAPPProtocol