当前位置:网站首页>349. intersection of two arrays
349. intersection of two arrays
2022-06-09 10:08:00 【Mr Gao】
349. Intersection of two arrays
Given two arrays nums1 and nums2 , return Their intersection . Every element in the output must be only Of . We can Regardless of the order of the output results .
Example 1:
Input :nums1 = [1,2,2,1], nums2 = [2,2]
Output :[2]
Example 2:
Input :nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output :[9,4]
explain :[4,9] It is also passable
This question is actually quite simple , We can solve the problem by setting up an auxiliary array :
The solution code is as follows :
/** * Note: The returned array must be malloced, assume caller calls free(). */
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){
int* a=(int* )malloc(sizeof(int)*1000);
int* b=(int* )malloc(sizeof(int)*1000);
int i=0;
for(i=0;i<1000;i++){
a[i]=0;
}
for(i=0;i<nums1Size;i++){
if(a[nums1[i]]==0){
a[nums1[i]]=1;
}
}
int p=0;
for(i=0;i<nums2Size;i++){
if(a[nums2[i]]==1){
a[nums2[i]]++;
b[p++]=nums2[i];
}
}
*returnSize=p;
return b;
}
边栏推荐
- Terraform 学习总结(6)—— 基于阿里云平台上的 Terraform 实战
- 【科技、商业和管理】看剧学创业:《硅谷》第五季第1-3集
- 1340. 跳跃游戏 V-动态规划加dfs
- 2220. 转换数字的最少位翻转次数
- Minimum path sum
- 基于云的 LDAP 入门(上)
- 349. 两个数组的交集
- MSF基于SSH协议的信息收集
- Machine learning notes - breast cancer classification using keras and deep learning
- LeetCode_ Sort_ Medium_ 406. reconstruct the queue based on height
猜你喜欢

Visual slam Summary - superpoint / superglue

机器学习笔记 - R语言学习入门系列一

八、线性规划 顶点、极值点和基本可行解决方案
![[technology, business and management] drama learning and Entrepreneurship: Silicon Valley Season 6 Episode 3-5](/img/67/65df8f06d9019c3fc2f089ea52b541.png)
[technology, business and management] drama learning and Entrepreneurship: Silicon Valley Season 6 Episode 3-5

MSF tips

【科技、商业和管理】看剧学创业:《硅谷》第六季第1-2集
![[1 data collection] complete learning path of data crawler](/img/73/5224cc4476f05aa190c135eea0aafd.jpg)
[1 data collection] complete learning path of data crawler
![[practical skills] from the book](/img/f5/b3480e0b9c39e729e8167e48bf255d.png)
[practical skills] from the book "beautiful teams"

【科技、商业和管理】看剧学创业:《硅谷》第五季第4-6集

机器学习笔记 - U-Net论文解读
随机推荐
Kubernetes第七篇:Pod进阶、Controller进阶、Resource和Dashboard
16. 最接近的三数之和-快速排序加双指针法
【 science, Technology, Business and management】 play Science and entrepreneurship: The Silicon Valley Saison 5 episodes 4 - 6
Composition of IT resources accessible anywhere, anytime
Openstack explanation (XX) -- neutron node principle
【科技、商业和管理】看剧学创业:《硅谷》第六季第6-7集
构建词表与抽样——【torch学习笔记】
【genius_platform软件平台开发】第三十六讲:内置数据类型的最大值宏定义
机器学习笔记 - Transformer/Attention论文解读
【科技、商业和管理】看剧学创业:《硅谷》第六季第3-5集
[probability theory] correlation calculation between variables
当你孤独,抑郁,焦虑的时候......请记得,还有风雨
8、 Vertices, extremum points and basic feasible solutions of linear programming
MSF practice - harm of ms17-010 vulnerability
- Bean method ‘redisConnectionFactory‘ in ‘JedisConnectionConfiguration‘ not loaded because @Conditi
【好书推荐】芯片产业科普书籍:《芯事》
MSF information collection based on TCP protocol
Use a query statement to query the number of people whose data is within the score range of 0-60,60-80,80-100
剑指 Offer II 061. 和最小的 k 个数对-大顶堆法
Troubleshooting of soaring memory utilization of redis cluster instances