N 将小于 1000 且确保是 2 的整次幂。 如果你想了解更多关于四叉树的知识，你可以参考这个wiki页面。

/*
// Definition for a QuadTree node.
class Node {
public:
bool val;
bool isLeaf;
Node* topLeft;
Node* topRight;
Node* bottomLeft;
Node* bottomRight;
Node() {}
Node(bool _val, bool _isLeaf, Node* _topLeft, Node* _topRight, Node* _bottomLeft, Node* _bottomRight) {
val = _val;
isLeaf = _isLeaf;
topLeft = _topLeft;
topRight = _topRight;
bottomLeft = _bottomLeft;
bottomRight = _bottomRight;
}
};
*/
class Solution {
public:
Node* construct(vector<vector<int>>& grid) {
int N=grid.size();
if(N==0) return NULL;
int sum =0;
for(auto r:grid)
for(auto c: r)
sum +=c;
// cout<<sum<<endl;
if( sum== N*N || sum ==0)
{
return new Node(grid[0][0],true, NULL,NULL,NULL,NULL);
}
vector<vector<int>> tl(N/2,vector<int>(N/2,0));
vector<vector<int>> tr(N/2,vector<int>(N/2,0));
vector<vector<int>> bl(N/2,vector<int>(N/2,0));
vector<vector<int>> br(N/2,vector<int>(N/2,0));
bool ftl, ftr,fbl, fbr;
for(int i=0;i<N/2;i++)
for(int j=0;j<N/2;j++)
{
tl[i][j]=grid[i][j];
bl[i][j]=grid[i+N/2][j];
tr[i][j]=grid[i][j+N/2];
br[i][j]=grid[i+N/2][j+N/2];
}
return new Node(false,false,construct(tl),construct(tr),construct(bl),construct(br));
}
};