Say I have an int array called sequence with values
[1, 3, 2, 4, 3, 5, 4, 6, 1, 3]
I want to check if another instance of 1 exists besides the first one in the array, and if it does, I would like to get its index in the array.
So far, this is what I've done:
// Get the first and second number of the sequence array
int firstNumberIndex = 0;
int firstNumber = sequence[0];
int secondNumber = sequence[1];
// Check that firstNumber < secondNumber
if (firstNumber < secondNumber) {
// Remove firstNumber from the sequence array
instance = removeElement(sequence, firstNumberIndex);
// Check whether another instance of
// firstNumber exists in sequence array
if (contains(sequence, firstNumber)) {
// Here, I would like to get the index of
// the other instance of '1', for example
}
}
1an arbitrary number or is it always the first element?1is the first element, I want to find the index of its other occurrences