Maximum Number of Balls in a Box LeetCode solution in C++

1
class Solution {
2
public:
3
int countBalls(int lowLimit, int highLimit) {
4
vector<int> box(46, 0);
5
for (int i = lowLimit; i <= highLimit; i++) {
6
int sum = 0;
7
int temp = i;
8
while (temp) {
9
sum = sum + temp % 10;
10
temp = temp / 10;
11
}
12
box[sum]++;
13
}
14

15
return *max_element(box.begin(), box.end());
16
}
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0