We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d9db278 commit 450b10fCopy full SHA for 450b10f
Strings/src/BeautifulBinaryString.java
src/strings/BeautifulBinaryString.java
@@ -0,0 +1,25 @@
1
+// https://www.hackerrank.com/challenges/beautiful-binary-string/problem
2
+
3
+package strings;
4
5
+import java.util.Scanner;
6
7
+public class BeautifulBinaryString {
8
+ public static void main(String[] args) {
9
+ Scanner scanner = new Scanner(System.in);
10
+ int length = scanner.nextInt();
11
+ String string = scanner.next();
12
+ System.out.println(minimumSteps(string));
13
+ }
14
15
+ private static int minimumSteps(String string) {
16
+ int deletions = 0;
17
+ for (int index = 0 ; index < string.length() - 2 ; index++) {
18
+ if (string.charAt(index) == '0' && string.charAt(index + 1) == '1' && string.charAt(index + 2) == '0') {
19
+ deletions++;
20
+ index += 2;
21
22
23
+ return deletions;
24
25
+}
0 commit comments