leetcode算法题--地图中的最高点
原题链接:https://leetcode-cn.com/problems/map-of-highest-peak/
多源bfs
class Solution {public:vector<vector<int>> highestPeak(vector<vector<int>>& isWater) {int m = isWater.size(), n = isWater[0].size();vector<vector<int>> vec(m, vector<int>(n, -1));queue<pair<int, int>> que;int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};for (int i = 0; i < m; ++i) {for (int j = 0; j < n; ++j) {if (isWater[i][j] == 1) {vec[i][j] = 0;que.push({i, j});}}}while (que.size()) {auto p = que.front();int i = p.first, j = p.second;for (int k = 0; k < 4; ++k) {int x = i + dx[k], y = j + dy[k];if (x < 0 || y < 0 || x >= m || y >= n || vec[x][y] != -1 ) continue;vec[x][y] = vec[i][j] + 1;que.push({x, y});}que.pop();}return vec;}
};
leetcode算法题--地图中的最高点相关推荐
- leetcode算法题--矩阵中的幸运数
原题链接:https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix/ class Solution {public:vector<in ...
- leetcode算法题--二叉树中的最长交错路径★
原题链接:https://leetcode-cn.com/problems/longest-zigzag-path-in-a-binary-tree/ 嵌套递归(超时) 相关题目:二叉树中的列表 in ...
- leetcode算法题--二叉树中的列表★
原题链接:https://leetcode-cn.com/problems/linked-list-in-binary-tree/ 嵌套递归 bool isSubPath(ListNode* head ...
- leetcode算法题--二叉树中序遍历迭代法
原题链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 二叉树中序遍历迭代法,栈实现 vector<int> ...
- leetcode算法题--句子中的有效单词数
原题链接:https://leetcode-cn.com/problems/number-of-valid-words-in-a-sentence/ class Solution {public:in ...
- leetcode算法题--数组中两个数的最大异或值
原题链接:https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/ 1.方法一:暴力法 func findMax ...
- leetcode算法题--数组中数字出现的次数 II
原题链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/ int singleNumb ...
- leetcode算法题--数组中数字出现的次数
原题链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/ vector<int> ...
- leetcode算法题--圆圈中最后剩下的数字
原题链接:https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/ 反推: 人数为1: 0 ...
最新文章
- BZOJ 1492: [NOI2007]货币兑换Cash [CDQ分治 斜率优化DP]
- VS2008修改工程名
- javaweb学习总结(十)——HttpServletRequest对象(一)
- 【网络安全】NFS服务安全加固
- boost::static_min_max_signed_type用法的测试程序
- 在计算机技术方面用英语怎么说,“计算机应用技术”用英语怎么说?
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(40)-精准在线人数统计实现-【过滤器+Cache】...
- PC软件开发技术之二:用C#开发基于自动化接口的OPC客户端
- linux 集成调试工具,linux下can调试工具canutils安装过程记录
- C11标准和C++11标准
- 【python】六一新玩法turtle画哆啦A梦
- 网页框架布局设计_实用的网页设计-框架和框架用法介绍
- OC的单例模式的实现
- 【小程序模板】功能模块+红色招聘信息资讯小程序网页模板+行业职位招聘小程序+招聘信息网页下载
- 维视智造斩获2022年度光能杯最具影响力“智造”企业奖
- 有道笔记无法同步(笔录)
- 【毕业设计】深度学习+python+opencv实现动物识别 - 图像识别
- “极盾-2021”众测推荐名录发布,墨云科技荣誉登榜
- MYSQL数据库原理与应用-个人总结(上)
- ret和retf指令