原题链接: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算法题--地图中的最高点相关推荐

  1. leetcode算法题--矩阵中的幸运数

    原题链接:https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix/ class Solution {public:vector<in ...

  2. leetcode算法题--二叉树中的最长交错路径★

    原题链接:https://leetcode-cn.com/problems/longest-zigzag-path-in-a-binary-tree/ 嵌套递归(超时) 相关题目:二叉树中的列表 in ...

  3. leetcode算法题--二叉树中的列表★

    原题链接:https://leetcode-cn.com/problems/linked-list-in-binary-tree/ 嵌套递归 bool isSubPath(ListNode* head ...

  4. leetcode算法题--二叉树中序遍历迭代法

    原题链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ 二叉树中序遍历迭代法,栈实现 vector<int> ...

  5. leetcode算法题--句子中的有效单词数

    原题链接:https://leetcode-cn.com/problems/number-of-valid-words-in-a-sentence/ class Solution {public:in ...

  6. leetcode算法题--数组中两个数的最大异或值

    原题链接:https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/ 1.方法一:暴力法 func findMax ...

  7. leetcode算法题--数组中数字出现的次数 II

    原题链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/ int singleNumb ...

  8. leetcode算法题--数组中数字出现的次数

    原题链接:https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/ vector<int> ...

  9. leetcode算法题--圆圈中最后剩下的数字

    原题链接:https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/ 反推: 人数为1: 0 ...

最新文章

  1. BZOJ 1492: [NOI2007]货币兑换Cash [CDQ分治 斜率优化DP]
  2. VS2008修改工程名
  3. javaweb学习总结(十)——HttpServletRequest对象(一)
  4. 【网络安全】NFS服务安全加固
  5. boost::static_min_max_signed_type用法的测试程序
  6. 在计算机技术方面用英语怎么说,“计算机应用技术”用英语怎么说?
  7. ASP.NET MVC5+EF6+EasyUI 后台管理系统(40)-精准在线人数统计实现-【过滤器+Cache】...
  8. PC软件开发技术之二:用C#开发基于自动化接口的OPC客户端
  9. linux 集成调试工具,linux下can调试工具canutils安装过程记录
  10. C11标准和C++11标准
  11. 【python】六一新玩法turtle画哆啦A梦
  12. 网页框架布局设计_实用的网页设计-框架和框架用法介绍
  13. OC的单例模式的实现
  14. 【小程序模板】功能模块+红色招聘信息资讯小程序网页模板+行业职位招聘小程序+招聘信息网页下载
  15. 维视智造斩获2022年度光能杯最具影响力“智造”企业奖
  16. 有道笔记无法同步(笔录)
  17. 【毕业设计】深度学习+python+opencv实现动物识别 - 图像识别
  18. “极盾-2021”众测推荐名录发布,墨云科技荣誉登榜
  19. MYSQL数据库原理与应用-个人总结(上)
  20. ret和retf指令

热门文章

  1. python中文版编译器下载-python编译器
  2. 从官网下载的python包如何使用-如何下载python包
  3. python装饰器作用-python中装饰器的作用
  4. python写web难受-pythonweb为什么不火-问答-阿里云开发者社区-阿里云
  5. python常用命令大全-Python常用命令之集合
  6. python学习音频-详解python播放音频的三种方法
  7. python培训班排行榜-深圳python培训机构排行榜
  8. elasticsearch之查询扩展
  9. LeetCode Gray Code(回溯法)
  10. Interviews(内连接,左外连接,分组、聚合)