flameboi

0s modification and 1s

Mar 26th, 2021 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. public class Solution {
  2. public int solve(ArrayList<Integer> A, int B) {
  3. int zc = 0, len = 0, maxlen = 0, lent = 1;
  4. for (int i = 0; i < A.size(); i++) {
  5. if (A.get(i) == 1) {
  6. len++;
  7. }
  8. else if (A.get(i) == 0 && zc < B) {
  9. zc++;
  10. len++;
  11. }
  12. else if (A.get(i) == 0 && zc == B) {
  13. lent = 1;
  14. int zct = 1;
  15. for (int j = i - 1; j >= 0; j--) {
  16. if (A.get(i) == 1) {
  17. lent++;
  18. }
  19. else if (A.get(i) == 0 && zct < B) {
  20. zct++;
  21. lent++;
  22. }
  23. else if (A.get(i) == 0 && zct == B) {
  24. break;
  25. }
  26. }
  27. len = lent;
  28. }
  29. if (len > maxlen) maxlen = len;
  30. }
  31. return maxlen;
  32. }
  33. }
Add Comment
Please, Sign In to add comment