You are viewing a single comment's thread. Return to all comments →
Java:
public static int alternatingCharacters(String s) { if (s.length() <= 1) { return 0; } int deletions = 0; for (int i = 1; i < s.length(); i++) { if (s.charAt(i) == s.charAt(i - 1)) { deletions++; } } return deletions; }
Seems like cookies are disabled on this browser, please enable them to open this website
Alternating Characters
You are viewing a single comment's thread. Return to all comments →
Java: