You are viewing a single comment's thread. Return to all comments →
My complexity is here O(n^2). But eventually in fact are my steps equal to yours ?
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String message = scanner.nextLine().toUpperCase(); int counter = 0; if(message.length() > 0 && message.length() < 100 && message.length() % 3 == 0){ for(int i = 0; i < message.length() / 3 ; i++){ String str = message.substring(i * 3, (i + 1) * 3); int localCounter = 0; for(int j = 0; j < 3; j++){ if(!(str.charAt(j) == "SOS".charAt(j))) localCounter++; } counter += localCounter; } } System.out.println(counter); scanner.close(); }
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 →
My complexity is here O(n^2). But eventually in fact are my steps equal to yours ?