当前位置:网站首页>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;
}
}
边栏推荐
- C语言HashTable/HashSet库汇总
- The latest analysis of the main principals of hazardous chemical business units in 2022 and the simulated examination questions of the main principals of hazardous chemical business units
- [daily question] dichotomy - find a single dog (Bushi)
- 【DRM】DRM bridge驱动调用流程简单分析
- Null and undefined
- eth入门之简介
- Download and install captura and configure ffmpeg in captura
- Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information
- Commands related to the startup of redis under Linux server (installation and configuration)
- "Final review" 16/32-bit microprocessor (8086) basic register
猜你喜欢

【刷题篇】 找出第 K 小的数对距离

Arduino application development - LCD display GIF dynamic diagram

Interaction free shell programming

js实现在可视区内,文字图片动画效果

Appium automated testing framework

在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码

SAP ui5 application development tutorial 105 - detailed introduction to the linkage effect implementation of SAP ui5 master detail layout mode

CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle

The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade

Appium自动化测试框架
随机推荐
有监督预训练!文本生成又一探索!
Shardingsphere dynamic data source
Null and undefined
TCP/IP模型中的重磅嘉宾TCP--尚文网络奎哥
[national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
CVPR 2022 | 大连理工提出自校准照明框架,用于现实场景的微光图像增强
【刷题篇】 找出第 K 小的数对距离
深潜Kotlin协程(十九):Flow 概述
js中#号的作用
[Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
Use of sigaction
DAPP for getting started with eth
Practical operation of vim
树莓派如何连接WiFi
js/ts底层实现双击事件
For instruction, uploading pictures and display effect optimization of simple wechat applet development
Commands related to the startup of redis under Linux server (installation and configuration)
[brush questions] connected with rainwater (one dimension)
以两列的瀑布流为例,我们应该怎么构建每一列的数组
Intercept string fixed length to array