您的位置:首页 > 文旅 > 美景 > 湖南公司响应式网站建设价位_手机网络代理是什么意思_排名查询系统_磁力王

湖南公司响应式网站建设价位_手机网络代理是什么意思_排名查询系统_磁力王

2025/4/15 20:35:05 来源:https://blog.csdn.net/m0_73221020/article/details/146137680  浏览:    关键词:湖南公司响应式网站建设价位_手机网络代理是什么意思_排名查询系统_磁力王
湖南公司响应式网站建设价位_手机网络代理是什么意思_排名查询系统_磁力王

c++中的queue数据结构

q.empty()判断队列是否为空

q.front()访问队头元素

q.pop()删除队头元素

q.push(1)添加元素

class Solution {
public:vector<vector<int>> res;vector<vector<int>> levelOrder(TreeNode* root) {queue<TreeNode*> q;if(root == nullptr) return {};q.push(root);while(!q.empty()){vector<int> tem;int size = q.size();for(int i=0;i<size;i++){TreeNode* head = q.front(); //访问队头元素tem.push_back(head->val);q.pop();    //删除队头元素if(head->left!=nullptr) q.push(head->left);if(head->right != nullptr) q.push(head->right);}res.push_back(tem);}return res;}
};

回溯篇

17. 电话号码的字母组合 - 力扣(LeetCode)

匹配相关的题目

2850. 将石头分散到网格图的最少移动次数 - 力扣(LeetCode)

vector里面可以嵌pair,然后是用emplace_back插入

vector<pair<int,int>> from,to;int minimumMoves(vector<vector<int>>& grid) {for(int i=0;i<grid.size();i++){for(int j=0;j<grid[i].size();j++){if(grid[i][j]){for(int k=1;k<grid[j][j]){from.emplace_back(i,j);}}else{to.emplace_back(i,j);}}}    }

1947. 最大兼容性评分和 - 力扣(LeetCode)

next_permutation的使用,不能对二维数组

1. next_permutation的使用问题

  • next_permutation函数的作用是生成下一个字典序更大的排列。在你的代码中,students是一个二维数组,next_permutation不能直接对二维数组进行操作。

  • 如果你想通过排列来尝试所有可能的组合,可以尝试对mentors的索引进行排列,而不是直接对students进行排列。

class Solution {
public:int ans = 0;int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {int len = students.size();//初始化导师的索引数组vector<int> Index;for(int i=0;i<len;i++){Index.push_back(i);}do{int total = 0;for(int i=0;i<len;i++){for(int j=0;j<students[i].size();j++){if((students[i][j] == mentors[Index[i]][j])){total += 1;}}}ans = max(ans,total);}while(next_permutation(Index.begin(),Index.end()));return ans;}
};

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com