-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complement.java
44 lines (37 loc) · 897 Bytes
/
Complement.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Solve {
Vector<Integer> findRange(String str, int n) {
// code here
int count=0;
int l=-1;
int max=0;
int ansL=-1, ansR=-1;
for(int i=0;i<n;i++){
if(str.charAt(i)=='0'){
count++;
}
else{
count--;
if(count<0){
count=0;
l=-1;
}
}
if(count==1 && l==-1){
l=i;
}
if(count>max){
max=count;
ansL=l;
ansR=i;
}
}
Vector<Integer> ans=new Vector<>();
if(ansL==-1)
ans.add(-1);
else{
ans.add(ansL+1);
ans.add(ansR+1);
}
return ans;
}
}