[InterviewBit] Divisible by 60

Divisible by 60

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
int Solution::divisibleBy60(vector<int> &A) {
if(A.size() == 1) return A[0] == 0;
if(A.size() == 2) return (A[0] == 0 and A[1] == 6) or (A[0] == 6 and A[1] == 0);
int sum = 0, zero = 0;
for(auto a : A) {
if(a == 0) zero = 1;
sum += a;
}
return sum % 3 == 0 and zero;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/17/PS/interviewbit/divisible-by-60/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.