I don't know why it doesn't work. I checked it few times, didn't find any error and results are right, but still requirements are not fulfill
package com.codegym.task.task07.task0716;
import java.util.ArrayList;
/*
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("myle"); // 1
list.add("lye"); // 2
list.add("myre");
list.add("syle");
list.add("karl");
list.add("max");
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
// write your code here
for(int i = 0; i < list.size(); i++){
if(list.get(i).contains("r") && list.get(i).contains("l"))
{
return list;
}
else if(list.get(i).contains("r"))
{
list.remove(i);
i--;
}
else if(list.get(i).contains("l"))
{
list.add(list.get(i));
}
else{
return list;
}
}
return list;
}
}