当前位置:网站首页>Week 304 Dunk
Week 304 Dunk
2022-08-02 03:01:00 【Jack Ju】
1.Introduction
Do less code topic,Can't fall asleep today,I think she's right increasingly,我思考了下,Indeed there is a big probability,For ten years to do goal,There is a strong possibility cannot achieve.So did a few problem is reluctantly let oneself of mind.Sipping kraal mountain strong spirit,一边写Leetcode题目,还好第 304 Field force buckles weeks "the first is a simple question,Otherwise can't sleep tonight,But to admit that you do dishes,哈哈哈哈哈哈哈哈.
2.The description of Problems
- 使数组中所有元素都等于零
给你一个非负整数数组 nums .在一步操作中,你必须:
选出一个正整数 x ,x 需要小于或等于 nums 中 最小 的 非零 元素.
nums 中的每个正整数都减去 x.
返回使 nums 中所有元素都等于 0 需要的 最少 操作数.
示例 1:
输入:nums = [1,5,0,3,5]
输出:3
解释:
第一步操作:选出 x = 1 ,之后 nums = [0,4,0,2,4] .
第二步操作:选出 x = 2 ,之后 nums = [0,2,0,0,2] .
第三步操作:选出 x = 2 ,之后 nums = [0,0,0,0,0] .
示例 2:
输入:nums = [0]
输出:0
解释:nums 中的每个元素都已经是 0 ,所以不需要执行任何操作.
提示:
1 <= nums.length <= 100
0 <= nums[i] <= 100
3.My Solution
class Solution {
public:
int minimumOperations(vector<int>& nums) {
int count = 0;
int flag = 1;
int subflag = 1;
for(int i =0;i<nums.size();i++){
if(nums[i]>0){
subflag = 0;
}
}
if(subflag){
return 0;
}
while(flag){
flag = 0;
int min = 10000;
for(int i=0;i<nums.size();i++){
if(nums[i]<min && nums[i]!=0){
min = nums[i];
}
}
for(int i = 0;i<nums.size();i++){
if(nums[i]>0)
nums[i]-= min;
}
for(int i = 0;i<nums.size();i++){
if(nums[i] != 0){
flag = 1;
break;
}
}
count++;
}
return count;
}
};
边栏推荐
- 【LeetCode】144.二叉树的前序遍历
- PHP WebShell 免杀
- [LeetCode] 94. Inorder traversal of binary tree
- 【LeetCode】144. Preorder Traversal of Binary Tree
- (1) Redis: Key-Value based storage system
- Chapter 11_Database Design Specifications
- MySQL8.0.26安装配置教程(windows 64位)
- Heuristic merge, DSU on Tree
- node:internal/modules/cjs/loader:936 throw err; ^ Error: Cannot find module ‘./scope‘
- AcWing 1285. Word Problem Solving (AC Automata)
猜你喜欢
ROS2自学笔记:launch文件完整编写流程
2W字!详解20道Redis经典面试题!(珍藏版)
2W字!梳理50道经典计算机网络面试题(收藏版)
PHP WebSehll backdoor script and detection tool
CentOS7安装Oracle数据库的全流程
22-08-01 西安 尚医通(01)跨域配置、Swagger2、R类、统一异常处理和自定义异常、Logback日志
合奥科技网络 面试(含参考答案)
ASP WebShell backdoor script and anti-kill
aws s3 upload file
WebShell连接工具(中国菜刀、WeBaCoo、Weevely)使用
随机推荐
数仓:数仓从ETL到ELT架构的转化以及俩者的区别
2W字!详解20道Redis经典面试题!(珍藏版)
咨询cdc for oracle,增量同步scan.startup.mode只有initial和la
MySQL修改最大连接数限制
直击程序员面试现场:百度面试官都问了我些啥?
centos安装mysql8
DVWA安装教程(懂你的不懂·详细)
MySQL8.0.26安装配置教程(windows 64位)
aws s3上传文件
【LeetCode】94.二叉树的中序遍历
MySQL函数(经典收藏)
VPS8702 VPSC(源特科技)电源管理(PMIC) 封装SOT23-6
【LeetCode】20. Valid parentheses
Flask 报错:WARNING This is a development server. Do not use it in a production deployment
【LeetCode】83.删除排序链表中的重复元素
【LeetCode】1374. 生成每种字符都是奇数个的字符串
详解最强分布式锁工具:Redisson
Redis主从、哨兵、 Cluster集群一锅端!
亲身经历过的面试题
mysql8.0.28 download and installation detailed tutorial, suitable for win11