在第二个向量中查找向量元素
给定两个整数向量,如何确定第一个向量中的某些元素是否存在于第二个向量中?
Given two vectors of integers, how to determinate if there's some element from 1st vector is present in 2nd one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想这样的事情应该有效:
I guess something like this should work:
您可以获取两个向量的 set_intersection ,然后检查所得交集是否为空:
set_intersection
可以在#include
中找到。要使
set_intersection
起作用,必须首先对两个向量进行排序。You could take the set_intersection of both vectors, and then check if the resulting intersection is empty:
set_intersection
can be found in#include <algorithm>
For
set_intersection
to work, both vectors must first be sorted.我想是这样的:
I think something like this: