fork download
  1. public class Solution {
  2. public ArrayList<Integer> flip(String A) {
  3. ArrayList<Integer> res = new ArrayList<Integer>();
  4. char[] carr = A.toCharArray();
  5. int n = carr.length;
  6. int[] arr = new int[n];
  7. for(int i = 0; i < n; ++i)
  8. arr[i] = carr[i]-'0';
  9. int cm = 0;
  10. int max = -1;
  11. int left = -1;
  12. int right = -1;
  13. int lVal = 0;
  14. for(int i = 0; i < n; ++i){
  15. if(arr[i] == 0)
  16. cm += 1;
  17. else
  18. cm -= 1;
  19. if(cm < 0){
  20. cm = 0;
  21. lVal = i + 1;
  22. }
  23. else {
  24. if(cm > max){
  25. max = cm;
  26. left = lVal;
  27. right = i;
  28. }
  29. }
  30. }
  31. if(left == -1)
  32. return res;
  33. res.add(left+1);
  34. res.add(right+1);
  35. return res;
  36. }
  37. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
Main.java:2: error: cannot find symbol
    public ArrayList<Integer> flip(String A) {
           ^
  symbol:   class ArrayList
  location: class Solution
Main.java:3: error: cannot find symbol
        ArrayList<Integer> res = new ArrayList<Integer>();
        ^
  symbol:   class ArrayList
  location: class Solution
Main.java:3: error: cannot find symbol
        ArrayList<Integer> res = new ArrayList<Integer>();
                                     ^
  symbol:   class ArrayList
  location: class Solution
4 errors
stdout
Standard output is empty