LeetCode
小何童鞋
Camera Tuning工程师
展开
-
LeetCode-3(二叉树的深度(最大深度))
树的遍历方式总体分为两类:深度优先搜索(DFS)、广度优先搜索(BFS); 常见的 DFS : 先序遍历、中序遍历、后序遍历; 常见的 BFS : 层序遍历(即按层遍历)。 方法一:后序遍历(DFS) 递归实现 class Solution { public int maxDepth(TreeNode root) { if(root==null)return 0; else return Math.max(maxDepth(root.left),maxDepth(r原创 2020-08-22 15:34:27 · 166 阅读 · 0 评论 -
LeetCode-2(二叉树的最小深度)
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public int minDepth(TreeNode root) { if (root == nu.原创 2020-08-21 21:19:54 · 80 阅读 · 0 评论 -
LeetCode-1(两数之和)
class Solution { public int[] twoSum(int[] nums, int target) { for (int i = 0; i < nums.length; i++) { for (int j = i+1; j < nums.length; j++) { if(nums[i] + nums[j] == target){ // 返回索引的位置.原创 2020-08-21 20:28:37 · 125 阅读 · 0 评论