Hi everyone. Been working on this exercise for a few hours and I don't understand my the third test condition does not pass. I'm also not really satisfied with the code structure (additional hints on how to make it cleaner are highly appreciated) but for now a bit of help to help me understand what's missing will be more important.
Thanks a ton!
package com.codegym.task.task07.task0716;
import java.util.ArrayList;
import java.util.Collections;
/*
R or L
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> list = new ArrayList<String>();
list.add("rose"); // 0
list.add("measure"); // 1
list.add("love"); // 2
list.add("live");
list.add("lyre");
list.add("wade");
list.add("love");
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
int i = 0;
while (i <= list.size()) {
if (i >= list.size()) break;
if (list.get(i).contains("r") && list.get(i).contains("l")) {
i++;
continue;
}
if (list.get(i).contains("r") && !list.get(i).contains("l")) {
list.remove(i);
i = 0;
continue;
}
if (list.get(i).contains("l") && !list.get(i).contains("r")) {
list.add(i + 1,list.get(i));
i = i + 2;
}
else i++;
}
return list;
}
}