Skip to content

Commit 450b10f

Browse files
solves beautiful binary string
1 parent d9db278 commit 450b10f

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

Strings/src/BeautifulBinaryString.java

-33
This file was deleted.
+25
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)