public static ArrayList<String> fix(ArrayList<String> list) {
for (int x = 0; x<list.size(); x++) {
if (list.get(x).contains("r")){
if (list.get(x).contains("l")){
}
else {
list.remove(x);
x--;
}
}
else if (list.get(x).contains("l")){
if (list.get(x).contains("r")){
continue;
}
else {
list.add(x);
x++;
}
}
}
return list;
}
}
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("love"); // 1
list.add("lyre"); // 2
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
for (int x = 0; x<list.size(); x++) {
if (list.get(x).contains("r")){
if (list.get(x).contains("l")){
}
else {
list.remove(x);
x--;
}
}
else if (list.get(x).contains("l")){
if (list.get(x).contains("r")){
continue;
}
else {
list.add(x);
x++;
}
}
}
return list;
}
}