class Solution {
public:intmaximalSquare(vector<vector<char>>& matrix){if(matrix.empty())return0;int n = matrix.size(), m = matrix[0].size();
vector<vector<int>>f(n +1, vector<int>(m +1,0));int res =0;for(int i =1; i <= n; i ++)for(int j =1; j <= m; j ++)if(matrix[i -1][j -1]!='0'){
f[i][j]=min(f[i -1][j],min(f[i][j -1], f[i -1][j -1]))+1;
res =max(res, f[i][j]);}return res * res;}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:intcountNodes(TreeNode* root){if(!root)return0;returncountNodes(root->left)+countNodes(root->right)+1;}};
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:intcountNodes(TreeNode* root){if(!root)return0;int l =0, r =0;
TreeNode *leftP = root,*rightP = root;while(leftP){
l ++;
leftP = leftP->left;}while(rightP){
r ++;
rightP = rightP->right;}if(l == r)return(1<< l)-1;return1+countNodes(root->left)+countNodes(root->right);}};
class Solution {
public:intcomputeArea(int A,int B,int C,int D,int E,int F,int G,int H){longlong x =min(C, G)+0ll-max(A, E);longlong y =min(D, H)+0ll-max(B, F);return(C - A)*(D - B)-max(0ll, x)*max(0ll, y)+(G - E)*(H - F);}};
class Solution {
public:voidcalc(stack<char>&op, stack<int>&num)//把栈顶两个数拿出来操作{int x = num.top(); num.pop();int y = num.top(); num.pop();if(op.top()=='+') num.push(y + x);else num.push(y - x);
op.pop();}intcalculate(string s){
stack<char> op;
stack<int> num;for(int i =0; i < s.size(); i ++){char c = s[i];if(c ==' ')continue;if(c =='('|| c =='+'|| c =='-') op.push(c);elseif(c ==')'){
op.pop();//弹出对应的左括号if(op.size()&& op.top()!='(')calc(op, num);}else{int j = i;while(j < s.size()&&isdigit(s[j])) j ++;
num.push(atoi(s.substr(i, j - i).c_str()));
i = j -1;if(op.size()&& op.top()!='(')//不是左括号先计算两个calc(op, num);}}return num.top();}};
class MyStack {
public:
queue<int> q;/** Initialize your data structure here. */MyStack(){}/** Push element x onto stack. */voidpush(int x){
q.push(x);}/** Removes the element on top of the stack and returns that element. */intpop(){int n = q.size();while(n -->1) q.push(q.front()), q.pop();int x = q.front();
q.pop();return x;}/** Get the top element. */inttop(){int n = q.size();while(n -->1) q.push(q.front()), q.pop();int x = q.front();
q.pop(), q.push(x);return x;}/** Returns whether the stack is empty. */
bool empty(){return q.empty();}};/**
* Your MyStack object will be instantiated and called as such:
* MyStack* obj = new MyStack();
* obj->push(x);
* int param_2 = obj->pop();
* int param_3 = obj->top();
* bool param_4 = obj->empty();
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
TreeNode*invertTree(TreeNode* root){if(!root)return0;swap(root->left ,root->right);invertTree(root->left);invertTree(root->right);return root;}};
class Solution {
public:intcalculate(string s){if(s.size()==0)return0;int res =0;
stack<int> stk;int num =0;char sign ='+';for(int i =0; i <s.size(); i ++){if(s[i]>='0'&& s[i]<='9'){
num *=10;
num = num -'0'+ s[i];}if(s[i]=='+'|| s[i]=='-'|| s[i]=='*'|| s[i]=='/'|| i == s.size()-1){if(sign =='+')
stk.push(num);if(sign =='-')
stk.push(-num);if(sign =='*'){int top = stk.top();
stk.pop();
stk.push(num * top);}if(sign =='/'){int top = stk.top();
stk.pop();
stk.push(top / num);}
sign = s[i];
num =0;}}while(!stk.empty()){int top = stk.top();
res += top;
stk.pop();}return res;}};
class Solution {
public:
string rangeToString(int st,int ed){if(st == ed)returnto_string(st);returnto_string(st)+"->"+to_string(ed);}
vector<string>summaryRanges(vector<int>& nums){
vector<string> res;if(nums.empty())return res;int st = nums[0], ed = nums[0];for(int i =1; i < nums.size(); i ++){int x = nums[i];if(x > ed +1){
res.push_back(rangeToString(st, ed));
st = ed = x;}else ed ++;}
res.push_back(rangeToString(st, ed));return res;}};
class Solution {public: int maximalSquare(vector<vector<char>>& matrix) { if(matrix.empty()) return 0; int n = matrix.size(), m = matrix[0].size(); vector...