高效名单交集算法

编程入门 行业动态 更新时间:2024-10-13 06:20:03
本文介绍了高效名单交集算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

由于两个列表(不一定排序),什么是最有效的非递归算法找到这些列表的交集?

Given two lists (not necessarily sorted), what is the most efficient non-recursive algorithm to find the intersection of those lists?

推荐答案

您可以把第一个列表中的所有元素成为哈希集合。然后,进行迭代,第二个,并且对于它的每个元素,检查散列,看它是否存在于第一列表。如果是这样,将它输出作为交点的元素

You could put all elements of the first list into a hash set. Then, iterate the second one and, for each of its elements, check the hash to see if it exists in the first list. If so, output it as an element of the intersection.

更多推荐

高效名单交集算法

本文发布于:2023-11-29 21:17:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647651.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高效   算法   名单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!