Hi everyone. Wen I put the code in IntelliJ IDE it work normally, But in CodyGem write me, that I have a problem. Please Help me to understand my problem.
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.add("measure"); // 3
list.add("wade"); // 4
list.add("bulk");
list = fix(list);
for (String s : list) {
System.out.println(s);
}
}
public static ArrayList<String> fix(ArrayList<String> list) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).contains("r") && list.get(i).contains("l")) {
i++;
} else if (list.get(i).contains("l") && !(list.get(i).contains("r"))) {
list.add(i,list.get(i));
i =i+1;
} else if (list.get(i).contains("r") && !list.get(i).contains("l")) {
list.remove(i);
if (i >= 0) {
i--;
} else {
i++;
}
}
}
return list;
}
}