当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
3D激光SLAM:LeGO-LOAM论文解读---完整篇
PyQt5快速开发与实战 9.5 PyQtGraph在PyQt中的应用 && 9.6 Plotly在PyQt中的应用
Unix知识:shell详细解读
【LeetCode】21. 合并两个有序链表
实现弹框组件
使用内存映射加快PyTorch数据集的读取
“带薪划水”偷刷阿里老哥的面经宝典,三次挑战字节,终成正果
SQL——左连接(Left join)、右连接(Right join)、内连接(Inner join)
【Web技术】1397- 深入浅出富文本编辑器
SQL去重的三种方法汇总
SQLSERVER merges subquery data into one field
IDEA 配置方法注释自动参数
1161. 最大层内元素和 (二叉树的层序遍历)
一、excel转pdf格式jacob.jar
「MySQL」- 基础增删改查
《MySQL高级篇》四、索引的存储结构
2022/7/28
7 天学个Go,Go 结构体 + Go range 来学学
KVM virtualization job
Redis缓冲穿透和缓冲击穿工具类的封装








