Check if there are any repeated elements in an array recursively
Posted
by devoured elysium
on Stack Overflow
See other posts from Stack Overflow
or by devoured elysium
Published on 2010-06-01T01:31:09Z
Indexed on
2010/06/01
2:43 UTC
Read the original article
Hit count: 255
I have to find recursively if there is any repeated element in an integer array v
.
The method must have the following signature:
boolean hasRepeatedElements(int[] v)
I can't see any way of doing that recursively without having to define another method or at least another overload to this method (one that takes for example the element to go after or something). At first I thought about checking for the current v
if there is some element equal to the first element, then creating a new array with L-1
elements etc but that seems rather inefficient. Is it the only way?
Am I missing here something?
© Stack Overflow or respective owner