当前位置:网站首页>Detailed explanation of Niuke - Gloves
Detailed explanation of Niuke - Gloves
2022-04-23 16:42:00 【Grow up, Leslie】
Original link : glove __ Cattle from
Their thinking :
1. First of all, consider that there are no gloves on both sides 0 The situation of
Take the one on the left as an example : Subtract the minimum number of colors from the number of all gloves on the left, and then +1, The above figure is the corresponding figure 17-2+1=16 only , in other words , Take... On the left 16 Gloves , sure Take out all the colors , Now just take one from the other hand and you can match it . Suppose to take 15 Gloves , Then there may be such a situation : Take it 4 Only yellow ,5 Only green ,6 Only blue ; Then you may not get the orange one , So take 15 A glove cannot 100% Take out all possible colors . Do the same for the one on the right , Judge which one is smaller on the left and right , Then the last value +1 It'll match .
2. There may be... On both sides 0 The situation of
The final code implementation :
class Gloves {
public:
int findMinimum(int n, vector<int> left, vector<int> right) {
// write code here
int sum=0;
int left_min=INT_MAX;
int right_min=INT_MAX;
int left_sum=0,right_sum=0;
for(int i=0;i<n;i++)
{
if(left[i]*right[i]==0)
sum+=left[i]+right[i];// If there is one for 0, We need to find out this situation
else
{
left_sum+=left[i];
left_min=left[i]<left_min?left[i]:left_min;
right_sum+=right[i];
right_min=right[i]<right_min?right[i]:right_min;
}
}
return sum+=(left_sum>right_sum?(right_sum-right_min+1):(left_sum-left_min+1))+1;
}
};
版权声明
本文为[Grow up, Leslie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231637283768.html
边栏推荐
猜你喜欢
MySql主从复制
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page
Pycham connects to the remote server and realizes remote debugging
Use if else to judge in sail software - use the title condition to judge
文件操作详解(2)
面试百分百问到的进程,你究竟了解多少
【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100
各大框架都在使用的Unsafe类,到底有多神奇?
随机推荐
On the value, breaking and harvest of NFT project
Gartner publie une étude sur les nouvelles technologies: un aperçu du métacosme
关于局域网如何组建介绍
05 Lua 控制结构
伪分布安装spark
How magical is the unsafe class used by all major frameworks?
How to quickly batch create text documents?
深入了解3D模型相关知识(建模、材质贴图、UV、法线),置换贴图、凹凸贴图与法线贴图的区别
【Pygame小游戏】10年前风靡全球的手游《愤怒的小鸟》,是如何霸榜的?经典回归......
LVM and disk quota
基于GPU实例的Nanopore数据预处理
Selenium IDE and XPath installation of chrome plug-in
阿里研发三面,面试官一套组合拳让我当场懵逼
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
Esxi encapsulated network card driver
Custom implementation of Baidu image recognition (instead of aipocr)
Force buckle-746 Climb stairs with minimum cost
Install MySQL on MAC
Cartoon: what are IAAs, PAAS, SaaS?
MySQL的btree索引和hash索引区别