当前位置:网站首页>Leecode swipe questions and record LCP 18 breakfast combination
Leecode swipe questions and record LCP 18 breakfast combination
2022-07-03 04:01:00 【Why is there a bug list】
topic
Xiaokou chooses a breakfast stand in the autumn market , One dimensional integer array staple The price of each staple food was recorded , One dimensional integer array drinks The price of each drink is recorded in . Small bucks plan to choose a staple food and a drink , And it doesn't cost more than x element . Please return the total number of purchase options for small deduction .
Be careful : The answer needs to be 1e9 + 7 (1000000007) Take the mold for the bottom , Such as : The initial result of calculation is :1000000008, Please return 1
Example 1:
Input :staple = [10,20,5], drinks = [5,5,2], x = 15
Output :6
explain : Little button 6 A purchase plan , The corresponding subscripts of the selected staple food and beverage in the array are respectively :
The first 1 Kind of plan :staple[0] + drinks[0] = 10 + 5 = 15;
The first 2 Kind of plan :staple[0] + drinks[1] = 10 + 5 = 15;
The first 3 Kind of plan :staple[0] + drinks[2] = 10 + 2 = 12;
The first 4 Kind of plan :staple[2] + drinks[0] = 5 + 5 = 10;
The first 5 Kind of plan :staple[2] + drinks[1] = 5 + 5 = 10;
The first 6 Kind of plan :staple[2] + drinks[2] = 5 + 2 = 7.
Example 2:
Input :staple = [2,1,1], drinks = [8,9,5,1], x = 9
Output :8
explain : Little button 8 A purchase plan , The corresponding subscripts of the selected staple food and beverage in the array are respectively :
The first 1 Kind of plan :staple[0] + drinks[2] = 2 + 5 = 7;
The first 2 Kind of plan :staple[0] + drinks[3] = 2 + 1 = 3;
The first 3 Kind of plan :staple[1] + drinks[0] = 1 + 8 = 9;
The first 4 Kind of plan :staple[1] + drinks[2] = 1 + 5 = 6;
The first 5 Kind of plan :staple[1] + drinks[3] = 1 + 1 = 2;
The first 6 Kind of plan :staple[2] + drinks[0] = 1 + 8 = 9;
The first 7 Kind of plan :staple[2] + drinks[2] = 1 + 5 = 6;
The first 8 Kind of plan :staple[2] + drinks[3] = 1 + 1 = 2;
Tips :
1 <= staple.length <= 10^5
1 <= drinks.length <= 10^5
1 <= staple[i],drinks[i] <= 10^5
1 <= x <= 2*10^5
answer
public class Solution {
public int breakfastNumber(int[] staple, int[] drinks, int x)
{
Arrays.sort(staple);
Arrays.sort(drinks);
int count = 0;
int j = drinks.length - 1;
for(int i = 0;i < staple.length; i++)
{
if(staple[i] >= x) break;
for(;j >= 0; j--)
{
if(staple[i] + drinks[j] <= x)
{
count = (count + j + 1) % 1000000007;
break;
}
}
}
return count;
}
}
边栏推荐
- Recursion: one dimensional linked lists and arrays
- 学会pytorch能干什么?
- Social phobia of contemporary young people (III)
- 【毕业季·进击的技术er】职场人的自白
- [brush questions] find the number pair distance with the smallest K
- [Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
- eth入门之DAPP
- What can learning pytorch do?
- Ffmpeg download and installation tutorial and introduction
- How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo
猜你喜欢
![[home push IMessage] software installation virtual host rental tothebuddy delay](/img/e7/eb20a773e4b674962f856d179a3769.jpg)
[home push IMessage] software installation virtual host rental tothebuddy delay

在 .NET 6 项目中使用 Startup.cs

Is it better to speculate in the short term or the medium and long term? Comparative analysis of differences

For instruction, uploading pictures and display effect optimization of simple wechat applet development

Web会话管理安全问题

2022 polymerization process examination questions and polymerization process examination skills

nodejs基础:浅聊url和querystring模块

In Net 6 project using startup cs

2022 tea master (primary) examination questions and tea master (primary) examination question bank

300+篇文献!一文详解基于Transformer的多模态学习最新进展
随机推荐
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
Makefile demo
Use of sigaction
[DRM] simple analysis of DRM bridge driver call process
Message queue addition failure
When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker
Deep dive kotlin synergy (20): build flow
Separable bonds and convertible bonds
JS实现图片懒加载
释放数据力量的Ceph-尚文网络xUP楠哥
[Apple Photo Album push] IMessage group anchor local push
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
Deep dive kotlin synergy (19): flow overview
Idea shortcut keys
因果AI,下一代可信AI的产业升级新范式?
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
[home push IMessage] software installation virtual host rental tothebuddy delay
Applet (continuous update)
In Net 6 project using startup cs