检查队列JAVA中的唯一一组整数 [英] Checking for a unique set of Integers within a Queue JAVA

查看:90
本文介绍了检查队列JAVA中的唯一一组整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法noMatch,其标题是:



public static boolean noMatch(Queue< integer> q)



采用项目'q'的队列,当且仅当q中包含的所有元素都不同时才返回true,否则返回false。



IF Q包含:1,2,3,4,5,6,7。然后noMatch返回true。

如果Q包含:1,2,3,4,5,6,7,7,7那么noMatch返回false。



如何成功实现?

The method noMatch whose heading is:

public static boolean noMatch(Queue <integer> q)

Takes a queue of items 'q' and returns true if and only if all the elements contained in q are all different, and false otherwise.

IF Q contains: 1,2,3,4,5,6,7. THEN noMatch returns true.
IF Q contains:1,2,3,4,5,6,7,7,7 THEN noMatch returns false.

How can this be implemented successfully?

推荐答案

假设队列的大小未知,并且可能很大 - 最简单的解决方案是对它们进行排序:然后复制就在一起,只需比较相邻值即可轻松发现。



但是既然这是你的功课,我就不会给你任何代码,而且实现由你决定。

虽然这是一项微不足道的任务!
Assuming the size of the queue is unknown, and could be large - the simplest solution is to sort them: Then duplicates are together and can be spotted easily just by comparing adjacent values.

But since this is your homework, I'll give you no code, and teh implementation is up to you.
It is a trivial task though!


这篇关于检查队列JAVA中的唯一一组整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆