class Solution {
public:
/**
* 最大正方形
* @param matrix char字符型vector<vector<>>
* @return int整型
*/
int solve(vector<vector<char> >& matrix) {
// write code here
if(matrix.empty()) return 0;
int row = matrix.size(),col = matrix[0].size();
//vector<vector<int>> dp(row,vector<int>(col));
vector<int> dp(col+1);
int res = 0;
for(int i=1;i<=row;i++){
int pre = 0;//记录左上
for(int j=1;j<=col;j++){
int tem = dp[j];//记录当前
if(matrix[i-1][j-1] == '1'){
dp[j] = min(dp[j-1],min(dp[j],pre))+1;
res = max(res,dp[j]);
}else dp[j] = 0;
pre = tem;//当前成为下一次的左上
}
}
return res*res;
}
};