public int maximalSquare2(char[][] matrix) {
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) return 0;

        int maxArea = 0;
        int[][] m = new int[2][matrix[0].length];
        for (int i = 0; i < matrix.length; ++i) {
            for (int j = 0; j < matrix[0].length; ++j) {
                if (i == 0 || j == 0) {
                    m[i % 2][j] = matrix[i][j] - '0';
                } else {
                    m[i % 2][j] = matrix[i][j] == '0' ? 0 : Math.min(m[(i - 1) % 2][j - 1], Math.min(m[(i - 1) % 2][j], m[i % 2][j - 1])) + 1;
                }
                maxArea = Math.max(maxArea, m[i % 2][j] * m[i % 2][j]);
            }
        }
        return maxArea;
    }