class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
if (root == NULL) return {};
queue<TreeNode*> q;
q.push(root);
vector<int> res;
while (!q.empty()) {
int sz = q.size();
while (sz--) {
TreeNode *cur = q.front();
q.pop();
if (sz == 0) res.push_back(cur -> val);
if (cur -> left) q.push(cur -> left);
if (cur -> right) q.push(cur -> right);
}
}
return res;
}
};
Time Complexity: O(n)
Space: O(n)