当前位置:网站首页>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;
}
}
边栏推荐
- 毕设-基于SSM宠物领养中心
- Mutex and rwmutex in golang
- QSAR model establishment script based on pytoch and rdkit
- 105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
- CEPH Shangwen network xUP Nange that releases the power of data
- [mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
- What is the correct way to compare ntext columns with constant values- What's the right way to compare an NTEXT column with a constant value?
- Bisher - based on SSM pet adoption center
- Use of sigaction
- Analysis of the reason why the server cannot connect remotely
猜你喜欢

2022 P cylinder filling examination content and P cylinder filling practice examination video

学会pytorch能干什么?

China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects

【刷题篇】接雨水(一维)

Is pytorch difficult to learn? How to learn pytorch well?

第十届中国云计算大会·中国站:展望未来十年科技走向

没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥

有监督预训练!文本生成又一探索!

nodejs基础:浅聊url和querystring模块

leetcode:297. Serialization and deserialization of binary tree
随机推荐
pytorch怎么下载?pytorch在哪里下载?
[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
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
Write it down once Net travel management background CPU Explosion Analysis
SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
【刷题篇】多数元素(超级水王问题)
golang xxx. Go code template
Social phobia of contemporary young people (III)
记一次 .NET 差旅管理后台 CPU 爆高分析
[Apple Photo Album push] IMessage group anchor local push
pytorch项目怎么跑?
Shardingsphere dynamic data source
Dynamic programming: Longest palindrome substring and subsequence
MPLS setup experiment
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
Recursive use and multi-dimensional array object to one-dimensional array object
eth入门之DAPP
leetcode:297. 二叉树的序列化与反序列化