The output is right
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("lyre"); // 1
list.add("love"); // 2
list.add("measure");
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 x = 0; x < list.size(); ++x) {
if ((list.get(x).contains("r")) && (list.get(x).contains("l")))
++x;
else if ((list.get(x).contains("r")) && !(list.get(x).contains("l"))) {
list.remove(x);
if (x > 0)
--x;
}
else if ((list.get(x).contains("l")) && !(list.get(x).contains("r"))) {
list.add(x, list.get(x));
x = x + 1;
}
else
++x;
}
return list;
}
}