Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author scode
- */
- public class CountOnes4mString {
- // Returns count of n length binary
- // strings with consecutive 1's
- static int countStrings(int n) {
- int a[] = new int[n], b[] = new int[n];
- a[0] = b[0] = 1;
- for (int i = 1; i < n; i++) {
- a[i] = a[i - 1] + b[i - 1];
- b[i] = a[i - 1];
- }
- return (1 << n) - a[n - 1] - b[n - 1];
- }
- public static void main(String[] args) {
- String s = "110011111101111011111";
- int op = 0;
- String subs[] = s.split("0");
- for (String s1 : subs) {
- op = s1.length() > op ? s1.length() : op;
- }
- System.out.println(op);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement