极米笔试(09-19)
15单选+10多选+1编程+1数据库+1脑筋急转弯?????
编程题:求二叉树最右下角的节点值,我的思路是简单BFS
int find(TreeNode* root) { queue<TreeNode*> q; if(root == nullptr) return 0; vector<int> ans; q.push(root); while(!q.empty()){ ans.clear(); int len = q.size(); for(int i = 0; i < len; i++){ TreeNode* pNode = q.front(); q.pop(); if(pNode->left != nullptr) q.push(pNode->left); if(pNode->right != nullptr) q.push(pNode->right); ans.push_back(pNode->val); } } return ans[ans.size() - 1]; }
希望能等到面试通知吧~