03 2024 档案
摘要:94. 二叉树的中序遍历 https://leetcode.cn/problems/binary-tree-inorder-traversal/description/?envType=study-plan-v2&envId=top-100-liked // 递归 // List<Integer>
阅读全文
摘要:LRU https://leetcode.cn/problems/lru-cache/description/?envType=study-plan-v2&envId=top-100-liked class LRUCache { HashMap<Integer,DLinkedNode> map; i
阅读全文
摘要:区分 默认背包问题都先遍历物品(物品重量)再遍历背包(背包大小)但是不绝对 0-1背包问题遍历背包时逆序, 完全背包问题遍历背包时正序 求最大价值,dp初始值就小点(一般0就行),求最小价值,dp初始值就大点(找个数 Interger最大值或者背包大小+1W这种) 完全背包中 如果求组合数(顺序无关
阅读全文
摘要:70. 爬楼梯 https://leetcode.cn/problems/climbing-stairs/description/?envType=study-plan-v2&envId=top-100-liked public int climbStairs(int n) { if (n <= 1
阅读全文
摘要:数位dp https://leetcode.cn/problems/reverse-bits-lcci/description/ public int reverseBits(int num) { int max = 0; int dp1 = 0; int dp2 = 0; for (int i =
阅读全文
摘要:160. 相交链表 https://leetcode.cn/problems/intersection-of-two-linked-lists/description/?envType=study-plan-v2&envId=top-100-liked public ListNode getInte
阅读全文
摘要:53. 最大子数组和 https://leetcode.cn/problems/maximum-subarray/description/?envType=study-plan-v2&envId=top-100-liked public int maxSubArray(int[] nums) { i
阅读全文
摘要:155. 最小栈 https://leetcode.cn/problems/min-stack/description/?envType=study-plan-v2&envId=top-100-liked class MinStack { Deque<Integer> deque; Priority
阅读全文
摘要:513. 找树左下角的值 https://leetcode.cn/problems/find-bottom-left-tree-value/description/ public int findBottomLeftValue(TreeNode root) { int val = 0; Deque<
阅读全文
摘要:215. 数组中的第K个最大元素 https://leetcode.cn/problems/kth-largest-element-in-an-array/description/?envType=study-plan-v2&envId=top-100-liked public int findKt
阅读全文
摘要:110. 平衡二叉树 https://leetcode.cn/problems/balanced-binary-tree/description/ public boolean isBalanced(TreeNode root) { int balance = balance(root); retu
阅读全文
摘要:35. 搜索插入位置 https://leetcode.cn/problems/search-insert-position/description/?envType=study-plan-v2&envId=top-100-liked public int searchInsert(int[] nu
阅读全文
摘要:104. 二叉树的最大深度 https://leetcode.cn/problems/maximum-depth-of-binary-tree/description/ public int maxDepth(TreeNode root) { return max(root); } public i
阅读全文
摘要:226. 翻转二叉树 https://leetcode.cn/problems/invert-binary-tree/description/ public TreeNode invertTree(TreeNode root) { invert(root); return root; } publi
阅读全文
摘要:二叉树的递归遍历 递归三要素:确定递归函数的参数和返回值,确定终止条件,确定单层递归的逻辑 144. 二叉树的前序遍历 https://leetcode.cn/problems/binary-tree-preorder-traversal/description/ public List<Integ
阅读全文
摘要:239. 滑动窗口最大值 https://leetcode.cn/problems/sliding-window-maximum/description/ public int[] maxSlidingWindow(int[] nums, int k) { int[] res = new int[n
阅读全文
摘要:20. 有效的括号 https://leetcode.cn/problems/valid-parentheses/description/ public boolean isValid(String s) { if (s == null) return true; Stack<Character>
阅读全文
摘要:
阅读全文
摘要:232. 用栈实现队列 https://leetcode.cn/problems/implement-queue-using-stacks/description/ class MyQueue { Stack<Integer> stackIn; Stack<Integer> stackOut; pu
阅读全文
摘要:**28. 实现 strStr() ** https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string/description/ public void getNext(int[] next,Strin
阅读全文
摘要:73. 矩阵置零 https://leetcode.cn/problems/set-matrix-zeroes/description/?envType=study-plan-v2&envId=top-100-liked public void setZeroes(int[][] matrix) {
阅读全文
摘要:454. 四数相加 II https://leetcode.cn/problems/4sum-ii/description/、 public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { int res
阅读全文
摘要:242. 有效的字母异位词 https://leetcode.cn/problems/valid-anagram/description/ public boolean isAnagram(String s, String t) { char[] sChar = s.toCharArray(); c
阅读全文
摘要:283. 移动零 https://leetcode.cn/problems/move-zeroes/description/?envType=study-plan-v2&envId=top-100-liked public void moveZeroes(int[] nums) { int r =
阅读全文
摘要:24. 两两交换链表中的节点 https://leetcode.cn/problems/swap-nodes-in-pairs/description/ public ListNode swapPairs(ListNode head) { if (head == null || head.next
阅读全文
摘要:203. 移除链表元素 https://leetcode.cn/problems/remove-linked-list-elements/description/ public ListNode removeElements(ListNode head, int val) { if (head ==
阅读全文
摘要:1.两数之和 https://leetcode.cn/problems/two-sum/description/?envType=study-plan-v2&envId=top-100-liked public int[] twoSum(int[] nums, int target) { HashM
阅读全文
摘要:977.有序数组的平方 https://leetcode.cn/problems/squares-of-a-sorted-array/description/ public static int[] sortedSquares(int[] nums){ int left = 0; int right
阅读全文
摘要:1768.交替合并字符串 https://leetcode.cn/problems/merge-strings-alternately/description/?envType=study-plan-v2&envId=leetcode-75 public String mergeAlternatel
阅读全文
摘要:704.二分查找 https://leetcode.cn/problems/binary-search/description/ 一、左闭右闭 `//左闭右闭 public static int erFen1(int[] nums,int target){ if (target < nums[0]
阅读全文