当前位置:网站首页>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;
}
};
边栏推荐
- aws s3 upload file
- “带薪划水”偷刷阿里老哥的面经宝典,三次挑战字节,终成正果
- 就瞎写=感想
- 非稳压 源特电子 隔离电源模块芯片 5W VPS8504B 24V
- Go简单实现协程池
- "Paid paddling" stealthily brushes Brother Ali's face scriptures, challenges bytes three times, and finally achieves positive results
- MySQL8--Windows下使用msi(图形界面)安装的方法
- 第11章_数据库的设计规范
- 指针数组和数组指针
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
猜你喜欢

知识体系树

centos安装mysql8

mysql8.0.28下载和安装详细教程,适配win11

Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL Web框架Gin(九)

- daily a LeetCode 】 【 9. Palindrome

PHP WebShell Free Kill

WebShell connection tools (Chinese kitchen knife, WeBaCoo, Weevely) use

svm.SVC application practice 1--Breast cancer detection

Nacos源码分析专题(二)-服务注册

Chapter 7 Noise analysis
随机推荐
Hit the programmer interview scene: What did Baidu interviewers ask me?
Tree Chain Segmentation-
直击程序员面试现场:百度面试官都问了我些啥?
【LeetCode】83.删除排序链表中的重复元素
第11章_数据库的设计规范
01-Node-Express系统框架搭建(express-generator)
mysql8.0.28下载和安装详细教程,适配win11
给你一个大厂面试的机会,你能面试上吗?进来看看!
第 304 场力扣周赛
OperatingSystemMXBean获取系统性能指标
JunitTest单元测试
MySQL索引优化实战
22-08-01 西安 尚医通(01)跨域配置、Swagger2、R类、统一异常处理和自定义异常、Logback日志
Flask之路由(app.route)详解
很有意思的经历,很有意思的项目--文件夹对比工具
just write blindly = feelings
PHP WebShell 免杀
leetcode 143. 重排链表
架构:分布式任务调度系统(SIA-Task)简介
iVX低代码平台系列详解 -- 概述篇(二)