高效的列表交集算法

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

给定两个列表(不一定要排序),找到这些列表的集合交集的最有效的非递归算法是什么?我不相信我可以使用哈希算法.

Given two lists (not necessarily sorted), what is the most efficient non-recursive algorithm to find the set intersection of those lists? I don't believe I have access to hashing algorithms.

推荐答案

您可以将第一个列表的所有元素放入一个哈希集中.然后,迭代第二个,对于它的每个元素,检查散列以查看它是否存在于第一个列表中.如果是,则将其作为交集的元素输出.

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 12:25:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高效   算法   列表

发布评论

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

>www.elefans.com

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