public int maximalRectangle3(char[][] matrix) {
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0)
            return 0;   
        int max = 0;
        int row = matrix.length;
        int col = matrix[0].length;
        
        int i, j;
        
        int[] height = new int[col]; 
        int[] left = new int[col];
        int[] right = new int[col];
        
        for (i = 0; i < col; i++) {
            height[i] = 0;
            left[i] = 0;
            right[i] = col;
        }
        
        for (i = 0; i < row; i++) {
            int lastLeft = 0;
            int lastRight = col;            
            for (j = 0; j < col; j++) {
                if (matrix[i][j] == '1') {
                    height[j]++;
                    left[j] = Math.max(left[j], lastLeft);
                } else {
                    lastLeft = j + 1;
                    height[j] = 0;
                    left[j] = 0;
                    right[j] = col;
                }
                
            }
            for (j = col-1; j >= 0; j--) {
                if (matrix[i][j] == '1') {
                    right[j] = Math.min(right[j], lastRight);
                    int area = height[j]*(right[j]-left[j]);
                    max = Math.max(max, area);
                } else {
                    lastRight = j;
                }
            }
        }
        
        
        
        return max;
    }