摘要: 543. 二叉树的直径 LeetCode_543 题目描述 代码实现 代码撰写的时候需要注意的是left+right+1会多算一个结点。 在返回最终答案的时候需要减去一个结点(树的高度决定的)。 /** * Definition for a binary tree node. * public cl 阅读全文
posted @ 2021-03-15 21:30 Garrett_Wale 阅读(59) 评论(0) 推荐(0) 编辑
摘要: 200. 岛屿数量 LeetCode_200 题目描述 代码实现 class Solution { int[][] direction = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; int m, n; public int numIslands(char[][] gri 阅读全文
posted @ 2021-03-15 21:07 Garrett_Wale 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 92. 反转链表 II LeetCode_92 题目描述 解法一:穿针引线法-模拟的思路 首先确定一个左边界start表示翻转开始的起始点。 在左右边界之间不断修改next指针指向下一个结点。 当遍历到右边界的下一个字符时开始翻转这一整段的链表。 class Solution { public Li 阅读全文
posted @ 2021-03-15 20:52 Garrett_Wale 阅读(90) 评论(0) 推荐(0) 编辑
摘要: 113. 路径总和 II LeetCode_113 题目描述 解法一:低效率的递归回溯 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode 阅读全文
posted @ 2021-03-15 19:26 Garrett_Wale 阅读(64) 评论(0) 推荐(0) 编辑