合集-算法
摘要:977.有序数组的平方 https://leetcode.cn/problems/squares-of-a-sorted-array/description/ public static int[] sortedSquares(int[] nums){ int left = 0; int right
阅读全文
摘要:203. 移除链表元素 https://leetcode.cn/problems/remove-linked-list-elements/description/ public ListNode removeElements(ListNode head, int val) { if (head ==
阅读全文
摘要:24. 两两交换链表中的节点 https://leetcode.cn/problems/swap-nodes-in-pairs/description/ public ListNode swapPairs(ListNode head) { if (head == null || head.next
阅读全文
摘要:704.二分查找 https://leetcode.cn/problems/binary-search/description/ 一、左闭右闭 `//左闭右闭 public static int erFen1(int[] nums,int target){ if (target < nums[0]
阅读全文
摘要:242. 有效的字母异位词 https://leetcode.cn/problems/valid-anagram/description/ public boolean isAnagram(String s, String t) { char[] sChar = s.toCharArray(); c
阅读全文
摘要:454. 四数相加 II https://leetcode.cn/problems/4sum-ii/description/、 public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { int res
阅读全文
摘要:**28. 实现 strStr() ** https://leetcode.cn/problems/find-the-index-of-the-first-occurrence-in-a-string/description/ public void getNext(int[] next,Strin
阅读全文
摘要:232. 用栈实现队列 https://leetcode.cn/problems/implement-queue-using-stacks/description/ class MyQueue { Stack<Integer> stackIn; Stack<Integer> stackOut; pu
阅读全文
摘要:20. 有效的括号 https://leetcode.cn/problems/valid-parentheses/description/ public boolean isValid(String s) { if (s == null) return true; Stack<Character>
阅读全文
摘要:239. 滑动窗口最大值 https://leetcode.cn/problems/sliding-window-maximum/description/ public int[] maxSlidingWindow(int[] nums, int k) { int[] res = new int[n
阅读全文
摘要:二叉树的递归遍历 递归三要素:确定递归函数的参数和返回值,确定终止条件,确定单层递归的逻辑 144. 二叉树的前序遍历 https://leetcode.cn/problems/binary-tree-preorder-traversal/description/ public List<Integ
阅读全文
摘要:226. 翻转二叉树 https://leetcode.cn/problems/invert-binary-tree/description/ public TreeNode invertTree(TreeNode root) { invert(root); return root; } publi
阅读全文
摘要:104. 二叉树的最大深度 https://leetcode.cn/problems/maximum-depth-of-binary-tree/description/ public int maxDepth(TreeNode root) { return max(root); } public i
阅读全文
摘要:110. 平衡二叉树 https://leetcode.cn/problems/balanced-binary-tree/description/ public boolean isBalanced(TreeNode root) { int balance = balance(root); retu
阅读全文
摘要:513. 找树左下角的值 https://leetcode.cn/problems/find-bottom-left-tree-value/description/ public int findBottomLeftValue(TreeNode root) { int val = 0; Deque<
阅读全文
摘要:530. 二叉搜索树的最小绝对差 https://leetcode.cn/problems/minimum-absolute-difference-in-bst/description/ TreeNode pre = null; int res = Integer.MAX_VALUE; public
阅读全文
摘要:77. 组合 https://leetcode.cn/problems/combinations/description/ List<List<Integer>> res = new ArrayList<>(); List<Integer> path = new ArrayList<>(); pub
阅读全文
摘要:797. 所有可能的路径 https://leetcode.cn/problems/all-paths-from-source-to-target/description/ List<List<Integer>> res; List<Integer> path; public List<List<I
阅读全文