-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2609.java
28 lines (27 loc) · 936 Bytes
/
_2609.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions.thirdthousand;
public class _2609 {
public static class Solution1 {
public int findTheLongestBalancedSubstring(String s) {
int longest = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '0') {
int zeroes = 0;
while (i < s.length() && s.charAt(i) == '0') {
i++;
zeroes++;
}
if (i < s.length()) {
int ones = 0;
while (i < s.length() && s.charAt(i) == '1') {
i++;
ones++;
}
longest = Math.max(longest, Math.min(ones, zeroes) * 2);
i--;
}
}
}
return longest;
}
}
}