Just want to throw a solution using integral image. Clearly it's not as fast as DP solution, but it's fun

```
class Solution {
public:
int maximalSquare(vector<vector<char>>& matrix) {
int rows = matrix.size();
if (rows == 0) return 0;
int cols = matrix[0].size();
if (cols == 0) return 0;
int val;
vector<vector<int> > image(rows+1, vector<int>(cols+1, 0)); // Integral image
for (int r = 1; r <= rows; r++){
for (int c = 1; c <= cols; c++){
val = (matrix[r-1][c-1] == '0' ? 0 : 1);
image[r][c] = val + image[r][c-1] + image[r-1][c] - image[r-1][c-1];
}
}
if (image[rows][cols] == 0) return 0;
int maxSize = 1;
for (int r = 0; r <= rows; r++){
for (int c = 0; c <= cols; c++){
for (int s = min(rows-r, cols-c); s >= maxSize; s--){
if (image[r+s][c+s] + image[r][c] - image[r][c+s] - image[r+s][c] == s * s) {
maxSize = s;
break;
}
}
}
}
return maxSize * maxSize;
}
};
```