查找数组中所有可能的对 [英] Find all possible pairs in an array

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

问题描述

当我尝试做这样的事情时,我意识到我真的需要上大学!

Its when I try to do stuff like this I realise I really need to go to university!

无论如何,我有一个字符串数组 (275),我需要遍历它们并在 Java 中创建所有可能对的字符串.

Anyway I have an array of strings (275) I need to loop through them and create strings of all the possible pairs, in Java.

我一直在学习递归,但我找不到答案.

I've been learning about recursion but I cant find the answer for this.

推荐答案

如果 abba 对不同,请执行:

In case pairs ab and ba are different, do:

for i=0 to array.length
  for j=0 to array.length
    if i == j skip
    else construct pair array[i], array[j] 

如果没有,请执行以下操作:

and if not, do something like this:

for i=0 to array.length-1
  for j=i+1 to array.length
    construct pair array[i], array[j] 

请注意,我假设数组包含唯一的字符串!

Note that I am assuming the array holds unique strings!

这篇关于查找数组中所有可能的对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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