当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
随机推荐
详解最强分布式锁工具:Redisson
IPFS部署及文件上传(golang)
2W字!梳理50道经典计算机网络面试题(收藏版)
EasyGBS平台播放视频时偶尔出现播放失败是什么原因?
启发式合并、DSU on Tree
【LeetCode】104.二叉树的最大深度
aws s3上传文件
【LeetCode】144. Preorder Traversal of Binary Tree
8万字带你入门Rust
mysql8.0.28下载和安装详细教程,适配win11
KICAD 小封装拉线卡顿问题 解决方法
Nacos source code analysis topic (1) - environment preparation
PAT甲级打卡-1001-1004
【LeetCode】206.反转链表
01-Node-Express系统框架搭建(express-generator)
JunitTest单元测试
WebShell连接工具(中国菜刀、WeBaCoo、Weevely)使用
Docker-compose安装mysql
Hit the programmer interview scene: What did Baidu interviewers ask me?
PHP WebSehll 后门脚本与检测工具









