合集-算法

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

点击右上角即可分享
微信分享提示