You are viewing a single comment's thread. Return to all comments →
Java
public static String happyLadybugs(String b) { if (!b.contains("_")) { int len = 1; for (int i = 0; i < b.length() - 1; i++) { if (b.charAt(i) != b.charAt(i + 1)) { if (len == 1) return "NO"; len = 1; } else { len++; } } if (len == 1) return "NO"; } else { List<String> arr = Arrays.asList(b.split("")); for (int i = 0; i < arr.size(); i++) { if (!arr.get(i).equals("_") && Collections.frequency(arr, arr.get(i)) < 2) { return "NO"; } } } return "YES"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →
Java