BFS
KRYON!
这个作者很懒,什么都没留下…
展开
-
[leetcode]5366. 检查网格中是否存在有效路径
解题思路:BFSAC的代码:struct Point{ int x,y; int d; Point(int _x, int _y, int _d) { x = _x, y = _y, d = _d; }};class Solution { bool isOk(int cur, int next, int dir)...原创 2020-03-22 22:07:55 · 201 阅读 · 0 评论 -
[leetcode]1368. 使网格图至少有一条有效路径的最小代价
dijistraclass Solution { int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0};public: int minCost(vector<vector<int>>& grid) { priority_queue<pair<in...原创 2020-03-02 22:14:59 · 204 阅读 · 0 评论 -
[leetcode]5170. 验证二叉树
层次遍历+setclass Solution {public: bool validateBinaryTreeNodes(int n, vector<int>& leftChild, vector<int>& rightChild) { vector<bool>visited1(n,false); ...原创 2020-02-23 18:05:57 · 144 阅读 · 0 评论 -
[leetcode]139. 单词拆分
1、递归+备忘录class Solution { string s; vector<string> wordDict; unordered_set<string>m_set; vector<int>memo;//memo[i]表示[i, size()-1]可不可拆分若干个单词连着 1可 0不可 -1不知道 int d...原创 2020-02-19 16:24:25 · 249 阅读 · 0 评论 -
[leetcode] 637. 二叉树的层平均值
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...原创 2020-02-06 23:24:57 · 61 阅读 · 0 评论 -
[leetcode]107. 二叉树的层次遍历 II
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla...原创 2020-02-06 23:10:40 · 69 阅读 · 0 评论 -
[leetcode]102. 二叉树的层次遍历
BFS/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */...原创 2020-02-06 21:56:58 · 89 阅读 · 0 评论 -
[leetcode]1306. 跳跃游戏 III
DFS解法class Solution { vector<bool>visited; vector<int>arr; int len;public: bool DFS(int pos) { if(arr[pos] == 0) { return true; ...原创 2019-12-30 21:03:21 · 250 阅读 · 1 评论 -
[leetcode]529. 扫雷游戏 DFS递归、BFS、DFS栈实现
https://leetcode-cn.com/problems/minesweeper/DFS步骤:1、给的x,y坐标位置是地雷board[x][y] == 'M',把那个位置标记为地雷·board[x][y] = ‘X’,返回。2、不是地雷board[x][y]=='E',检查下这个坐标相邻位置有没有地雷:没有,标记当前位置board[x][y]='B',8个方向递归;有,...原创 2019-12-23 14:58:44 · 209 阅读 · 0 评论 -
[leetcode]1293. 网格中的最短路径
struct Node{ int x, y; int rest; //还可以消几个障碍物 int dist; //距离 Node(int _x,int _y, int _rest, int _dist) :x(_x), y(_y), rest(_rest),dist(_dist){}};class Solution { stati...原创 2019-12-18 20:52:56 · 967 阅读 · 3 评论