当前位置:网站首页>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 innums2innums1/strong> A list of integers.answer[1]is different< of all notexisting innums1innums2/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.
边栏推荐
- “带薪划水”偷刷阿里老哥的面经宝典,三次挑战字节,终成正果
- oracle优化:instr做join条件很慢「建议收藏」
- MySQL 行级锁(行锁、临键锁、间隙锁)
- Creation of doubly linked list
- Intranet Penetration Learning (IV) Domain Lateral Movement - SMB and WMI Service Utilization
- Usage of JOIN in MySQL
- darknet 硬件软件环境的设置和检测
- 最新MySql安装教学,非常详细
- KVM virtualization job
- Insertion and deletion of doubly linked list
猜你喜欢
随机推荐
医院管理系统数据库,课程设计,SQLserver,纯代码设计
Experience innovation and iteration through the development of a lucky draw applet
Intranet Penetration Learning (IV) Domain Lateral Movement - SMB and WMI Service Utilization
众多mock工具,这一次我选对了
基于Multisim的函数信号发生器–方波、三角波、正弦波[通俗易懂]
Redis-基础
The principle of v-model
Can I find a Go job in 7 days?Learn Go with arrays and pointers
分布式id解决方案
[Go Affair] See through Go's collections and slices at a glance
Redis缓冲穿透和缓冲击穿工具类的封装
What does "chmod 777-R filename" mean?
SQLSERVER merges subquery data into one field
unity-shader-2
WSL2安装.NET 6
【LeetCode】203.移除链表元素
最新MySql安装教学,非常详细
SQL study notes - REGEXP operator
【Web技术】1397- 深入浅出富文本编辑器
FCN中制作自己的数据集并进行训练









