Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
609 B
2
Indexable
Never
class Solution {
public:
    long long countCompleteDayPairs(vector<int>& hours) 
    {
        long long count[24]={0};
        long long n = hours.size();
        for(int i=0;i<n;i++)
        {
            hours[i] = hours[i]%24;
            count[hours[i]]++;
        }
        long long ans=0;
        for(int i=0;i<24;i++)
        {
          if(i==12 || i==0)
          {
            ans = ans + count[i]*(count[i]-1);
          }
          else
          {
            ans = ans + (count[i]*count[24-i]);
          }
        }
        ans = ans/2;
        return ans;
    }
};
Leave a Comment