项目场景:
Day1 Leetcode-1742
- 盒子中小球的最大数量
问题描述
`class Solution {
1、其中 int count;这句话没有定义初始变量 有脏数据 后面运算出现溢出问题
2、其中问题为 int j=lowLimit; 导致参与计算的值一直没变 出现问题
public:
int countBalls(int lowLimit, int highLimit) {
int box[46]={0};
int max=0;
for(int i=lowLimit;i<=highLimit+1;i++)
{
int count;
int j=lowLimit;
while(j>0)
{
count+=j%10;
j/=10;
}
if(max<(++box[count]))
max=box[count];
}
return max;
}
};
原因分析:
主要原因没有手算 手算后问题就很容易发现