Hi, i cant seem to find whats wrong with my code. If i could get
some help please * @param list * @param target * @return the SECOND
index at which target exists in the list passed. * return -1 if
list is null or target doesn't exist TWICE in the list. */ public
static int secondIndexOf(ArrayList list, int target) {
int count = 0;
int idx = 0;
if(list == null) {
return -1; }
for(int i = 0; i < list.size(); i++) {
if(list.get(i) == target) {
count++; } }'
if(count == 2) {
return list.indexOf(target); }
return -1; }
Hi, i cant seem to find whats wrong with my code. If i could get some help please * @param list * @param target * @retur
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Hi, i cant seem to find whats wrong with my code. If i could get some help please * @param list * @param target * @retur
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!