Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. /**
  2. *
  3. * @author scode
  4. */
  5. public class CountOnes4mString {
  6.  
  7. // Returns count of n length binary
  8. // strings with consecutive 1's
  9. static int countStrings(int n) {
  10. int a[] = new int[n], b[] = new int[n];
  11. a[0] = b[0] = 1;
  12.  
  13. for (int i = 1; i < n; i++) {
  14. a[i] = a[i - 1] + b[i - 1];
  15. b[i] = a[i - 1];
  16. }
  17. return (1 << n) - a[n - 1] - b[n - 1];
  18. }
  19.  
  20. public static void main(String[] args) {
  21. String s = "110011111101111011111";
  22. int op = 0;
  23. String subs[] = s.split("0");
  24. for (String s1 : subs) {
  25. op = s1.length() > op ? s1.length() : op;
  26. }
  27. System.out.println(op);
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement