You are viewing a single comment's thread. Return to all comments →
We need to keep track of the position since an S could also be changed for an O. So just counting isn't enough
public static int marsExploration(String s) { int counter = 0; int position = 1; for(int i = 0; i < s.length(); i++){ System.out.println(position); if((position == 1 || position == 3) && s.charAt(i) != 'S') { counter++; }else if(position == 2 && s.charAt(i) != 'O'){ counter++; } if(position == 3){ position = 1; }else{ position++; } } return counter; }
Seems like cookies are disabled on this browser, please enable them to open this website
Mars Exploration
You are viewing a single comment's thread. Return to all comments →
We need to keep track of the position since an S could also be changed for an O. So just counting isn't enough