随笔分类 -  leetCode hot 100

摘要:给你两个 版本号字符串 version1 和 version2 ,请你比较它们。版本号由被点 '.' 分开的修订号组成。修订号的值 是它 转换为整数 并忽略前导零。 比较版本号时,请按 从左到右的顺序 依次比较它们的修订号。如果其中一个版本字符串的修订号较少,则将缺失的修订号视为 0。 返回规则如下 阅读全文
posted @ 2026-03-07 10:12 MarkLeeBYR 阅读(4) 评论(0) 推荐(0)
摘要:二叉树中的路径被定义为一条节点序列,序列中每对相邻节点之间都存在一条边。同一个节点在一条路径序列中至多出现一次 。该路径 至少包含一个节点,且不一定经过根节点。 路径和是路径中各节点值的总和。 给你一个二叉树的根节点 root ,返回其 最大路径和 。 class Solution { int ma 阅读全文
posted @ 2024-02-04 15:19 MarkLeeBYR 阅读(30) 评论(0) 推荐(0)
摘要:public List<Integer> postorderTraversal(TreeNode root) { List<Integer> list = new ArrayList<>(); if (root == null) return list; Stack<TreeNode> stack 阅读全文
posted @ 2024-01-04 17:47 MarkLeeBYR 阅读(27) 评论(0) 推荐(0)
摘要:Solution 1://非递归 public List<Integer> preorderTraversal(TreeNode root) { List<Integer> result = new ArrayList<>(); if (root == null) { return result; 阅读全文
posted @ 2024-01-04 17:45 MarkLeeBYR 阅读(24) 评论(0) 推荐(0)
摘要:输入321,需要输出123 public static int reverse(int x) { int res = 0; while (x != 0) { // 下一步要res*10,所以这一步要保证res*10不大于 Integer.MAX_VALUE if (Math.abs(res) > I 阅读全文
posted @ 2024-01-04 17:29 MarkLeeBYR 阅读(22) 评论(0) 推荐(0)
摘要:和题目108类似:108是数组 https://www.cnblogs.com/MarkLeeBYR/p/16906818.html public TreeNode sortedListToBST(ListNode head) { if (head == null) { return null; } 阅读全文
posted @ 2024-01-04 16:25 MarkLeeBYR 阅读(22) 评论(0) 推荐(0)
摘要:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of 阅读全文
posted @ 2023-10-16 14:25 MarkLeeBYR 阅读(22) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, 阅读全文
posted @ 2023-10-09 22:43 MarkLeeBYR 阅读(22) 评论(0) 推荐(0)
摘要:不修改原来树的结构 public TreeNode mergeTrees(TreeNode t1, TreeNode t2) { if (t1 == null) { return t2; } if (t2 == null) { return t1; } // 先合并根节点 TreeNode root 阅读全文
posted @ 2023-04-13 11:25 MarkLeeBYR 阅读(27) 评论(0) 推荐(0)
摘要:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = 阅读全文
posted @ 2023-03-20 11:38 MarkLeeBYR 阅读(29) 评论(0) 推荐(0)
摘要:给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。 public class Solution { int max = 0; public int diameterOfBinaryTree(TreeNode root) 阅读全文
posted @ 2023-03-17 16:56 MarkLeeBYR 阅读(31) 评论(0) 推荐(0)
摘要:Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all 阅读全文
posted @ 2023-03-16 19:20 MarkLeeBYR 阅读(45) 评论(0) 推荐(0)
摘要:You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose o 阅读全文
posted @ 2023-03-16 19:17 MarkLeeBYR 阅读(35) 评论(0) 推荐(0)
摘要:给你一个含 n 个整数的数组 nums ,其中 nums[i] 在区间 [1, n] 内。请你找出所有在 [1, n] 范围内但没有出现在 nums 中的数字,并以数组的形式返回结果。 输入:nums = [4,3,2,7,8,2,3,1]输出:[5,6] public List<Integer> 阅读全文
posted @ 2023-03-16 19:10 MarkLeeBYR 阅读(29) 评论(0) 推荐(0)
摘要:public TreeNode insertNode(TreeNode root, TreeNode node) { // write your code here if(root == null){ return node; } if(root.val > node.val){ //这个树里面没有 阅读全文
posted @ 2023-03-16 19:07 MarkLeeBYR 阅读(27) 评论(0) 推荐(0)
摘要:给定两个字符串 s 和 p,找到 s 中所有 p 的 异位词 的子串,返回这些子串的起始索引。不考虑答案输出的顺序。 异位词 指由相同字母重排列形成的字符串(包括相同的字符串)。 输入: s = "cbaebabacd", p = "abc"输出: [0,6]解释:起始索引等于 0 的子串是 "cb 阅读全文
posted @ 2023-03-16 17:58 MarkLeeBYR 阅读(30) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/MarkLeeBYR/p/17166229.html 阅读全文
posted @ 2023-03-16 17:46 MarkLeeBYR 阅读(24) 评论(0) 推荐(0)
摘要:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both 阅读全文
posted @ 2023-03-16 17:22 MarkLeeBYR 阅读(43) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: Input: [1,3,5,4,7] Output: 2 Explanation: The two l 阅读全文
posted @ 2022-12-13 00:23 MarkLeeBYR 阅读(19) 评论(0) 推荐(0)
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input 阅读全文
posted @ 2022-12-02 11:34 MarkLeeBYR 阅读(28) 评论(0) 推荐(0)