随笔分类 -  LeetCode

摘要:day32 打卡122.买卖股票的最佳时机II 55. 跳跃游戏 45.跳跃游戏II 122.买卖股票的最佳时机II 122题目链接 class Solution { public int maxProfit(int[] prices) { int result = 0 ; for (int i = 阅读全文
posted @ 2023-04-01 10:24 zzzzzzsl 阅读(23) 评论(0) 推荐(0)
摘要:day31 打卡455.分发饼干 376. 摆动序列 53. 最大子数组和 455.分发饼干 455题目链接 class Solution { public int findContentChildren(int[] g, int[] s) { int count = 0; Arrays.sort( 阅读全文
posted @ 2023-03-31 11:58 zzzzzzsl 阅读(27) 评论(0) 推荐(0)
摘要:day30 打卡332. 重新安排行程 51. N 皇后 37. 解数独 332. 重新安排行程 332题目链接 去b站搜了视频讲解在写的。视频地址 class Solution { List<String> result = new ArrayList<>(); public List<Strin 阅读全文
posted @ 2023-03-30 16:40 zzzzzzsl 阅读(44) 评论(0) 推荐(0)
摘要:day29 打卡491.递增子序列 46.全排列 47.全排列 II 491.递增子序列 491题目链接 class Solution { List<List<Integer>> result = new ArrayList<>(); LinkedList<Integer> path = new L 阅读全文
posted @ 2023-03-30 09:43 zzzzzzsl 阅读(19) 评论(0) 推荐(0)
摘要:day28 打卡93.复原IP地址 78.子集 90.子集II 93.复原IP地址 93题目链接 class Solution { List<String> result = new ArrayList<>(); public List<String> restoreIpAddresses(Stri 阅读全文
posted @ 2023-03-28 09:28 zzzzzzsl 阅读(23) 评论(0) 推荐(0)
摘要:day27 打卡39. 组合总和 40.组合总和II 131.分割回文串 39. 组合总和 39题目链接 class Solution { List<List<Integer>> result = new ArrayList<>(); LinkedList<Integer> path = new L 阅读全文
posted @ 2023-03-27 22:35 zzzzzzsl 阅读(19) 评论(0) 推荐(0)
摘要:day25 打卡216.组合总和III 17.电话号码的字母组合 216.组合总和III 216题目链接 class Solution { List<List<Integer>> result = new ArrayList<>(); LinkedList<Integer> path = new L 阅读全文
posted @ 2023-03-25 12:03 zzzzzzsl 阅读(21) 评论(0) 推荐(0)
摘要:day24 打卡第77题. 组合 第77题. 组合 77题目链接 class Solution { List<List<Integer>> result = new ArrayList<>(); List<Integer> path = new LinkedList<>(); public List 阅读全文
posted @ 2023-03-24 13:12 zzzzzzsl 阅读(13) 评论(0) 推荐(0)
摘要:day23 打卡669. 修剪二叉搜索树 108.将有序数组转换为二叉搜索树 538.把二叉搜索树转换为累加树 669. 修剪二叉搜索树 669题目链接 1.迭代法 class Solution { public TreeNode trimBST(TreeNode root, int low, in 阅读全文
posted @ 2023-03-23 19:38 zzzzzzsl 阅读(18) 评论(0) 推荐(0)
摘要:day22 打卡235. 二叉搜索树的最近公共祖先 701.二叉搜索树中的插入操作 450.删除二叉搜索树中的节点 235. 二叉搜索树的最近公共祖先 235题目链接 1.递归法。利用二叉搜素树中间节点肯定大于左子树,小于右子树的特征。 class Solution { public TreeNod 阅读全文
posted @ 2023-03-22 15:49 zzzzzzsl 阅读(25) 评论(0) 推荐(0)
摘要:day21 打卡530.二叉搜索树的最小绝对差 501.二叉搜索树中的众数 236. 二叉树的最近公共祖先 530.二叉搜索树的最小绝对差 530题目链接 1.递归法——使用双指针。因为是二叉搜索树,所以中序遍历是递增的。所以最小值的产生肯定是前一个和后一个之间。 class Solution { 阅读全文
posted @ 2023-03-21 12:51 zzzzzzsl 阅读(17) 评论(0) 推荐(0)
摘要:day20 打卡654.最大二叉树 617.合并二叉树 700.二叉搜索树中的搜索 98.验证二叉搜索树 654.最大二叉树 654题目链接 1.看了视频链接之后按照思路写的。 class Solution { public TreeNode constructMaximumBinaryTree(i 阅读全文
posted @ 2023-03-20 16:40 zzzzzzsl 阅读(22) 评论(0) 推荐(0)
摘要:day18 打卡513.找树左下角的值 112. 路径总和 113.路径总和ii 106.从中序与后序遍历序列构造二叉树 105.从前序与中序遍历序列构造二叉树 513.找树左下角的值 513题目链接 1.我的想法:使用层次遍历,每次把每个层的第一个元素压进栈。最后把最后一个元素弹出来,就是最下面一 阅读全文
posted @ 2023-03-19 19:38 zzzzzzsl 阅读(21) 评论(0) 推荐(0)
摘要:day17 打卡110.平衡二叉树 257. 二叉树的所有路径 404.左叶子之和 110.平衡二叉树 110题目链接 1.递归法 class Solution { public boolean isBalanced(TreeNode root) { return getHeight(root) ! 阅读全文
posted @ 2023-03-17 15:11 zzzzzzsl 阅读(6) 评论(0) 推荐(0)
摘要:day16 打卡104.二叉树的最大深度 559. N 叉树的最大深度 111.二叉树的最小深度 222.完全二叉树的节点个数 104.二叉树的最大深度 104题目链接 1.递归法 class Solution { public int maxDepth(TreeNode root) { retur 阅读全文
posted @ 2023-03-16 14:32 zzzzzzsl 阅读(24) 评论(0) 推荐(0)
摘要:day15 打卡102. 二叉树的层序遍历 226.翻转二叉树 101.对称二叉树 2 102. 二叉树的层序遍历 102题目链接 1.使用队列 class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List< 阅读全文
posted @ 2023-03-15 16:08 zzzzzzsl 阅读(24) 评论(0) 推荐(0)
摘要:day14 打卡二叉树的递归遍历 迭代遍历 统一迭代 144. 二叉树的前序遍历 144题目链接 1.递归遍历 class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> list = 阅读全文
posted @ 2023-03-14 14:44 zzzzzzsl 阅读(20) 评论(0) 推荐(0)
摘要:day13 打卡239. 滑动窗口最大值 347.前 K 个高频元素 239. 滑动窗口最大值 239题目链接 1.看了视频在写的 class Solution { public int[] maxSlidingWindow(int[] nums, int k) { int index = 0; i 阅读全文
posted @ 2023-03-13 15:17 zzzzzzsl 阅读(18) 评论(0) 推荐(0)
摘要:day11 打卡20. 有效的括号 1047. 删除字符串中的所有相邻重复项 150. 逆波兰表达式求值 20. 有效的括号 20题目链接 1.本来使用的是Stack,时间2 ms,内存39.6 MB。而Deque时间1 ms,内存39.7 MB。 class Solution { public b 阅读全文
posted @ 2023-03-11 14:00 zzzzzzsl 阅读(15) 评论(0) 推荐(0)
摘要:day10 打卡232. 用栈实现队列 225. 用队列实现栈 232. 用栈实现队列 232题目链接 class MyQueue { // 管理进的元素 Stack<Integer> stackIn; // 管理出的元素 Stack<Integer> stackOut; public MyQueu 阅读全文
posted @ 2023-03-10 20:40 zzzzzzsl 阅读(14) 评论(0) 推荐(0)