当前位置:网站首页>1742. maximum number of small balls in the box
1742. maximum number of small balls in the box
2022-06-25 07:50:00 【AlbertOS】
introduce
You work in a toy factory that makes balls , Yes n n n A little ball , Number from l o w L i m i t lowLimit lowLimit Start , To h i g h L i m i t highLimit highLimit end ( Include l o w L i m i t lowLimit lowLimit and h i g h L i m i t highLimit highLimit , namely n = = h i g h L i m i t − l o w L i m i t + 1 ) n == highLimit - lowLimit + 1) n==highLimit−lowLimit+1). And there's an infinite number of boxes , Number from 1 1 1 To i n f i n i t y infinity infinity .
Your job is to put each ball in a box , The number of the box should be equal to the sum of each number on the ball number .
for example , Number 321 The ball should be numbered 3 + 2 + 1 = 6 Box , And number 10 The ball should be numbered 1 + 0 = 1 Box .
Here are two integers l o w L i m i t lowLimit lowLimit and h i g h L i m i t highLimit highLimit , Returns the number of balls in the box with the largest number of balls . If more than one box is enough to hold the most balls , Just return the number of balls in any box .
Example
Input :lowLimit = 1, highLimit = 10
Output :2
explain :
Box number :1 2 3 4 5 6 7 8 9 10 11 …
Number of balls :2 1 1 1 1 1 1 1 1 0 0 …
Number 1 I have the most balls in my box , The number of balls is 2 .
Input :lowLimit = 5, highLimit = 15
Output :2
explain :
Box number :1 2 3 4 5 6 7 8 9 10 11 …
Number of balls :1 1 1 1 2 2 1 1 1 0 0 …
Number 5 and 6 I have the most balls in my box , How many balls are in each box 2 .
Input :lowLimit = 19, highLimit = 28
Output :2
explain :
Box number :1 2 3 4 5 6 7 8 9 10 11 12 …
Number of balls :0 1 1 1 1 1 1 1 1 2 0 0 …
Number 10 I have the most balls in my box , The number of balls is 2 .
Answer key
My writing is more violent , Most of the small balls 9999 individual , So the maximum box label is 45, Create a 50 Array of , Sum the number of balls in each box result Results comparison , Take the bigger one , The last traversal is the number of balls in the largest box .
class Solution {
public:
int countBalls(int lowLimit, int highLimit) {
vector<int> sums(50);
int result = -1;
for(int i = lowLimit;i<=highLimit;++i){
int temp = i ,sum = 0;
while(temp !=0){
sum += temp%10;
temp/=10;
}
sums[sum]++;
result = max(result,sums[sum]);
}
return result;
}
};
边栏推荐
猜你喜欢

传统的IO存在什么问题?为什么引入零拷贝的?

Modular programming of LCD1602 LCD controlled by single chip microcomputer

一文了解 | 革兰氏阳性和阴性菌区别,致病差异,针对用药

Elk + filebeat log parsing, log warehousing optimization, logstash filter configuration attribute
![[distillation] pointdistiller: structured knowledge distillationwards efficient and compact 3D detection](/img/5c/ad42474a363c33ecc0e01890b65bbf.png)
[distillation] pointdistiller: structured knowledge distillationwards efficient and compact 3D detection

OAuth 2.0一键登录那些事

基于RBAC 的SAAS系统权限设计

Modular programming of oled12864 display controlled by single chip microcomputer

CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据

Do you know why the PCB produces tin beads? 2021-09-30
随机推荐
一“石”二“鸟”,PCA有效改善机载LiDAR林下地面点部分缺失的困局
The method of judging whether triode can amplify AC signal
1464. 数组中两元素的最大乘积
【QT】qtcreator便捷快捷键以及QML介绍
useMemo模拟useCallback
opencv最小值滤波(不局限于图像)
國外LEAD域名郵箱獲取途徑
Estimation of dense forest volume based on LIDAR point cloud with few ground points
权限、认证系统相关名词概念
Misunderstanding of switching triode
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_ scale_ factor‘
VectorDraw Developer Framework 10.10
基于RBAC 的SAAS系统权限设计
CAN总线工作状况和信号质量“体检”
传统的IO存在什么问题?为什么引入零拷贝的?
Five causes of PCB board deformation and six solutions 2021-10-08
[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)
Pcb|about FPC reinforcement type
What are the benefits of reserving process edges for PCB production? 2021-10-25
国外LEAD域名邮箱获取途径