当前位置:网站首页>leetcode——错误的集合
leetcode——错误的集合
2022-06-24 07:07:00 【编程SHARE】
错误的集合

解题思路
建一个有序的集合,数据从小到大1~n。然后依次遍历原集合,原集合里面的数据出现一次就把有序集合中的该数据制成0,当遍历的时候有序集合出现为0的情况,就找到了重复的一个数值,当遍历完的时候,有序集合中非0的就是缺少的数值。
时间复杂度O(n),空间复杂度O(n)
代码
int* findErrorNums(int* nums, int numsSize, int* returnSize){
*returnSize=2;
int* duibi=(int*)malloc(sizeof(int)*numsSize);
int* ret=(int*)malloc((*returnSize)*sizeof(int));
int i=0;
for(i=0;i<numsSize;i++)
duibi[i]=i+1;
for(i=0;i<numsSize;i++)
{
if(duibi[nums[i]-1] ==0)
ret[0]=nums[i];
else
duibi[nums[i]-1]=0;
}
for(i=0;i<numsSize;i++)
if(duibi[i]!=0)
ret[1]=duibi[i];
free(duibi);
return ret;
}
边栏推荐
- 2022春招面试总结
- À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL
- PHP代码加密+扩展解密实战
- 關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
- It is enough to read this article about ETL. Three minutes will let you understand what ETL is
- DataX User Guide
- Ordering of MySQL composite index
- 偶然间得到的framework工具类 自用
- 基于QingCloud的 “房地一体” 云解决方案
- every()、map()、forEarch()方法。数组里面有对象的情况
猜你喜欢

What is SRE? A detailed explanation of SRE operation and maintenance system
![[pytorch basic tutorial 30] code analysis of DSSM twin tower model](/img/4a/1f290990b39c517efb2b9cef0b5fcb.png)
[pytorch basic tutorial 30] code analysis of DSSM twin tower model

Telnet port login method with user name for liunx server

开源之夏中选名单已公示,基础软件领域成为今年的热门申请

一文讲透,商业智能BI未来发展趋势如何

【使用 PicGo+腾讯云对象存储COS 作为图床】

表单图片上传在Chorme中无法查看请求体的二进制图片信息

Prompt code when MySQL inserts Chinese data due to character set problems: 1366

Liunx Mysql安装

数据中台:数据中台技术架构详解
随机推荐
从华为WeAutomate数字机器人论坛,看政企领域的“政务新智理”
2022春招面试总结
1844. 将所有数字用字符替换
数据中台:中台架构及概述
【E325: ATTENTION】vim编辑时报错
Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system
Using sonar for code checking
110. 平衡二叉树-递归法
String to Base64
Pymysql inserts data into MySQL and reports an error for no reason
[force deduction 10 days SQL introduction] Day3
K8S部署高可用postgresql集群 —— 筑梦之路
Jenkins is deployed automatically and cannot connect to the dependent service [solved]
教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5
什么是SRE?一文详解SRE运维体系
双指针模拟
定时备份数据库脚本
Analyze the meaning of Internet advertising terms CPM, CPC, CPA, CPS, CPL and CPR
[10 day SQL introduction] Day2
MySQL | 视图《康师傅MySQL从入门到高级》笔记