当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢

MySQL8.0.28安装教程

mysql使用on duplicate key update批量更新数据

第10章_索引优化与查询优化

生成器知道鉴别器在无条件GANs中应该学习什么

centos安装mysql8

- daily a LeetCode 】 【 9. Palindrome

暴力破解全攻略

"Paid paddling" stealthily brushes Brother Ali's face scriptures, challenges bytes three times, and finally achieves positive results

MySQL index optimization in practice

PHP WebSehll 后门脚本与检测工具
随机推荐
feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
架构:应用架构的演进以及微服务架构的落地实践
启发式合并、DSU on Tree
Chapter 10_Index Optimization and Query Optimization
MySQL8--Windows下使用压缩包安装的方法
Nacos源码分析专题(一)-环境准备
MySQL索引优化实战
Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)
ASP WebShell backdoor script and anti-kill
svm.SVC application practice 1--Breast cancer detection
Docker-compose安装mysql
[LeetCode] 94. Inorder traversal of binary tree
微服务:微智能在软件系统的简述
递归检查配置项是否更变并替换
svm.SVC应用实践1--乳腺癌检测
总体写作原则
iVX低代码平台系列详解 -- 概述篇(二)
OperatingSystemMXBean to get system performance metrics
PHP WebSehll 后门脚本与检测工具