当前位置:网站首页>Life is endless, there are more questions, simple questions to learn knowledge points
Life is endless, there are more questions, simple questions to learn knowledge points
2022-07-31 11:07:00 【The wind is like a bro】
Easy difficulty 7 Favorites and sharing switch to English to receive dynamic feedback
Given you two integer arrays nums1
and nums2
with subscripts starting from 0
, please return an array of length 2
A list of answer
where:
answer[0]
is different< of all notexisting innums2
innums1
/strong> A list of integers.answer[1]
is different< of all notexisting innums1
innums2
/strong> A list of integers.
Note: The integers in the list can be returned in any order.
Example 1:
Input:nums1 = [1,2,3], nums2 = [2,4,6]Output:[[1,3],[4,6]]Explanation:For nums1, nums1[1] = 2 appears in nums2 at subscript 0, whereas nums1[0] = 1 and nums1[2] = 3 do not appear in nums2.Therefore, answer[0] = [1,3].For nums2, nums2[0] = 2 appears in nums1 at index 1, whereas nums2[1] = 4 and nums2[2] = 6 do not appear in nums2.Therefore, answer[1] = [4,6].
Example 2:
Input:nums1 = [1,2,3,3], nums2 = [1,1,2,2]Output:[[3],[]]Explanation:For nums1, nums1[2] and nums1[3] do not appear in nums2.Since nums1[2] == nums1[3] , both values only need to appear once in answer[0], so answer[0] = [3].Every integer in nums2 appears in nums1, so answer[1] = [] .
Tip:
1 <= nums1.length, nums2.length <= 1000
-1000 <= nums1[i], nums2[i] <= 1000
Pass 10,795Submit 16,126
Problem solution: The title has said so much, but it is actually the difference between the two sets.This C++ has been implemented, and it can be called directly.
class Solution {public:vector> findDifference(vector& nums1, vector& nums2) {set s1(nums1.begin(), nums1.end());set s2(nums2.begin(), nums2.end());vector v1, v2;set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), back_inserter(v1));set_difference(s2.begin(), s2.end(), s1.begin(), s1.end(), back_inserter(v2));return {v1, v2};}};
If the operation of other sets is encountered, then add it.
边栏推荐
猜你喜欢
LeetCode 1161.最大层内元素和:层序遍历
众多mock工具,这一次我选对了
Windows系统Mysql8版本的安装教程
KVM virtualization job
SQL——左连接(Left join)、右连接(Right join)、内连接(Inner join)
[Part 1 of Cloud Native Monitoring Series] A detailed explanation of Prometheus monitoring system
Windows安装mysql详细步骤(通俗易懂,简单上手)
3D激光SLAM:LeGO-LOAM论文解读---完整篇
【Web技术】1397- 深入浅出富文本编辑器
ApiPost 真香真强大,是时候丢掉 Postman、Swagger 了
随机推荐
mpu9150(driverack pa简明教程)
SQL力扣刷题七
Yarn安装配置(vsftpd安装配置)
unity-shader-2
【Go事】一眼看穿 Go 的集合和切片
解决报错TypeError:unsupported operand type(s) for +: ‘NoneType‘ and ‘str‘
web安全入门-黑苹果MAC系统安装
【虚拟化生态平台】树莓派安装虚拟化平台操作流程
1161. 最大层内元素和 (二叉树的层序遍历)
突破传统可靠性测试:混沌工程优秀实践
【LeetCode】203.移除链表元素
最全phpmyadmin漏洞汇总
新人学习小熊派华为iot介绍
单点登录原理及实现方式
SQLSERVER将子查询数据合并拼接成一个字段
WSL2安装.NET 6
拥抱趋势!阿里这套微服务开源框架权威手册,实战到底层细致清晰
一、excel转pdf格式jacob.jar
How SQL intercepts specified characters from strings (three functions of LEFT, MID, RIGHT)
Experience innovation and iteration through the development of a lucky draw applet