MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / binString

Method binString

SplitBinaryString.java:1–19  ·  view source on GitHub ↗
(String str)

Source from the content-addressed store, hash-verified

1 public static int binString(String str)
2 {
3 int countZero=0;
4 int countOne=0;
5 int ans=0;
6 for(int i=0;i<str.length();i++)
7 {
8 if(str.charAt(i)=='0') countZero++;
9 else countOne++;
10
11 if(countOne==countZero)
12 {
13 ans++;
14 countZero=0;
15 countOne=0;
16 }
17 }
18 return (ans==0)?-1:ans;
19 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected