How to compare two arrays of integers order-insensitively

前端 未结 8 1304
梦谈多话
梦谈多话 2021-01-19 13:23

I want Java code that can compare in this way (for example):

<1 2 3 4>  = <3 1 2 4>
<1 2 3 4> != <3 4 1 1>

I can\'t

8条回答
  •  感动是毒
    2021-01-19 13:58

    I think it would be sensible to check that the lengths of both arrays are equal before doing any iterating. It's a cheap way to opt out of hard work early, and it fixes the following type of failure for the second approach you mention:

    {1, 2, 3} seen as equal to {4, 3, 2, 1}

提交回复
热议问题