摘要:
左边大顶堆,右边小顶堆。右边数量比左边多一,左边放小的那半数,右边放大的那半 是偶数个,那就返回两个根堆的头结点的q平均值,如果是奇数,就是小根堆的数量大于大根堆数量1个,返回小根堆的头; 当左右平等数量的时候,往小根堆了加入,当小根堆大于大根堆时候,往大根堆里加入 1 priority_queue 阅读全文
摘要:
参考:https://zhuanlan.zhihu.com/p/31498036 https://www.jianshu.com/p/83bb10ad1d32 阅读全文
摘要:
1 vector<int> getLeastNumber(vector<int>& arr,int k){ 2 vector<int> vec(k,0); 3 if(0==k) 4 return vec; 5 priority_queue<int> q; 6 for(int i = 0;i < k; 阅读全文
摘要:
1 Node* pre = NULL,*cur = BULL; 2 Node* treeToDoubleyList(Node* root){//二叉搜索树中序遍历有序 3 if(root == NULL) 4 return NULL; 5 Node* dummy = new Node; 6 dumm 阅读全文
摘要:
1 vector<vector<int>> pathSum(TreeNode* root,int sum){//DFS遍历获取适合路径,当递归到叶子结点且sum为0,表示该路径合适 2 vector<vector<int>> ans; 3 vector<int> path; 4 5 helper(r 阅读全文
摘要:
1 string serialize(TreeNode* root) {//层序便利,将空的子节点也放入到字符串 2 ostringstream out; 3 queue<TreeNode*> q; 4 q.push(root); 5 while(q.size()){ 6 auto node = q 阅读全文