dfs
NCY_92377
Far from being a good programmer
展开
-
剑指 Offer 27. 二叉树的镜像
剑指 Offer 27. 二叉树的镜像请完成一个函数,输入一个二叉树,该函数输出它的镜像。例如输入: 4 / \ 2 7 / \ / \1 3 6 9镜像输出: 4 / \ 7 2 / \ / \9 6 3 1示例 1:输入:root = [4,2,7,1,3,6,9]输出:[4,7,2,9,6,3,1]限制:0 <= 节点个数 <= 1000解题思路dfs 交换roo原创 2020-08-05 22:06:13 · 112 阅读 · 0 评论 -
剑指 Offer 55 - I. 二叉树的深度
剑指 Offer 55 - I. 二叉树的深度输入一棵二叉树的根节点,求该树的深度。从根节点到叶节点依次经过的节点(含根、叶节点)形成树的一条路径,最长路径的长度为树的深度。例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回它的最大深度 3 。解题思路一、 DFS/递归(后序遍历)解1/** * Definition for a binary tree node. * str原创 2020-08-05 21:26:20 · 96 阅读 · 0 评论 -
leetcode695. 岛屿的最大面积
695. 岛屿的最大面积给定一个包含了一些 0 和 1 的非空二维数组 grid 。一个 岛屿 是由一些相邻的 1 (代表土地) 构成的组合,这里的「相邻」要求两个 1 必须在水平或者竖直方向上相邻。你可以假设 grid 的四个边缘都被 0(代表水)包围着。找到给定的二维数组中最大的岛屿面积。(如果没有岛屿,则返回面积为 0 。)示例 1:[[0,0,1,0,0,0,0,1,0,0,0,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,1,1,0,1,0,0,0,0,原创 2020-08-01 05:01:24 · 125 阅读 · 0 评论 -
计蒜客-迷宫(一)
题目: 计蒜客-迷宫(一)简单dfscode#include <bits/stdc++.h>using namespace std;char s[11][11];int n, m;bool FIND = false;bool vis[11][11];int dx[] = {-1, 0, 1, 0};int dy[] = {0, -1, 0, 1};voi...原创 2019-05-04 20:42:39 · 392 阅读 · 0 评论 -
1155 Heap Paths (30 分)
1155 Heap Paths (30 分)In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either grea...原创 2019-05-19 10:18:07 · 324 阅读 · 0 评论 -
1013 Battle Over Cities (25 分)
1013 Battle Over Cities (25 分)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We ...原创 2019-05-25 11:56:02 · 172 阅读 · 0 评论