Skip to content

Instantly share code, notes, and snippets.

@wang-nima
Created October 25, 2015 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wang-nima/92780af364355374e082 to your computer and use it in GitHub Desktop.
Save wang-nima/92780af364355374e082 to your computer and use it in GitHub Desktop.
像素比例
struct TreeNode {
bool color;
vector<TreeNode*> next;
TreeNode (bool c) : color(c), next(4, nullptr) {}
};
double getPercentage(TreeNode *root) {
if (next[0] == nullptr && next[1] == nullptr && next[2] == nullptr && next[3] == nullptr) {
return 1;
}
double sum = 0;
for (auto p : next) {
sum += getPercentage(p) / 4;
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment