摘要:
72. 编辑距离 LeetCode_72 题目描述 题解分析 代码实现 思路一 class Solution { public int minDistance(String word1, String word2) { int m = word1.length(); int n = word2.le 阅读全文
摘要:
144. 二叉树的前序遍历 LeetCode_144 题目描述 方法一:递归法 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode righ 阅读全文
摘要:
543. 二叉树的直径 LeetCode_543 题目描述 代码实现 代码撰写的时候需要注意的是left+right+1会多算一个结点。 在返回最终答案的时候需要减去一个结点(树的高度决定的)。 /** * Definition for a binary tree node. * public cl 阅读全文
摘要:
200. 岛屿数量 LeetCode_200 题目描述 代码实现 class Solution { int[][] direction = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; int m, n; public int numIslands(char[][] gri 阅读全文
摘要:
92. 反转链表 II LeetCode_92 题目描述 解法一:穿针引线法-模拟的思路 首先确定一个左边界start表示翻转开始的起始点。 在左右边界之间不断修改next指针指向下一个结点。 当遍历到右边界的下一个字符时开始翻转这一整段的链表。 class Solution { public Li 阅读全文
摘要:
113. 路径总和 II LeetCode_113 题目描述 解法一:低效率的递归回溯 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode 阅读全文
摘要:
64. 最小路径和 LeetCode_64 题目描述 代码实现 class Solution { public int minPathSum(int[][] grid) { int m = grid.length; int n = grid[0].length; int[][] dp = new i 阅读全文
摘要:
88. 合并两个有序数组 LeetCode_88 题目描述 方法一:暴力法 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { for(int i=0, j=0; j<n;){ if(i >= m 阅读全文
摘要:
199. 二叉树的右视图 LeetCode_199 题目描述 方法一:使用宽度优先搜索(类似于层次遍历,每次记录最后一个元素) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNo 阅读全文
摘要:
字节跳动2018校招大数据方向(第一批)编程题1 题目描述 P为给定的二维平面整数点集。定义 P 中某点x,如果x满足 P 中任意点都不在 x 的右上方区域内(横纵坐标都大于x),则称其为“最大的”。求出所有“最大的”点的集合。(所有点的横坐标和纵坐标都不重复, 坐标轴范围在[0, 1e9) 内) 阅读全文