随笔分类 -  leetCode hot 100

摘要:class Solution { private final Map<Character, String> phoneMap = new HashMap<Character, String>(); public void init() { phoneMap.put('2', "abc"); phon 阅读全文
posted @ 2024-02-05 10:41 MarkLeeBYR 阅读(11) 评论(0) 推荐(0) 编辑
摘要:示例 1: 输入:s = "3[a]2[bc]" 输出:"aaabcbc" 示例 2: 输入:s = "3[a2[c]]" 输出:"accaccacc" public static String decodeString(String s) { Stack<Integer> numStack = n 阅读全文
posted @ 2024-02-05 00:55 MarkLeeBYR 阅读(7) 评论(0) 推荐(0) 编辑
摘要:给定一个整数数组 temperatures ,表示每天的温度,返回一个数组 answer ,其中 answer[i] 是指对于第 i 天,下一个更高温度出现在几天后。如果气温在这之后都不会升高,请在该位置用 0 来代替。 示例 1: 输入: temperatures = [73,74,75,71,6 阅读全文
posted @ 2024-02-04 20:40 MarkLeeBYR 阅读(9) 评论(0) 推荐(0) 编辑
摘要:输入:text1 = "abcde", text2 = "ace" 输出:3 解释:最长公共子序列是 "ace" ,它的长度为 3 。 和题目72类似:https://www.cnblogs.com/MarkLeeBYR/p/16886489.html 这里需要维护一个二维的数组 dp,其大小为 m 阅读全文
posted @ 2024-02-04 17:12 MarkLeeBYR 阅读(25) 评论(0) 推荐(0) 编辑
摘要:二叉树中的路径被定义为一条节点序列,序列中每对相邻节点之间都存在一条边。同一个节点在一条路径序列中至多出现一次 。该路径 至少包含一个节点,且不一定经过根节点。 路径和是路径中各节点值的总和。 给你一个二叉树的根节点 root ,返回其 最大路径和 。 class Solution { int ma 阅读全文
posted @ 2024-02-04 15:19 MarkLeeBYR 阅读(8) 评论(0) 推荐(0) 编辑
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For 阅读全文
posted @ 2024-01-19 23:56 MarkLeeBYR 阅读(3) 评论(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 阅读(5) 评论(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 阅读(3) 评论(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 阅读(6) 评论(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 阅读(4) 评论(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 阅读(3) 评论(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:42 MarkLeeBYR 阅读(5) 评论(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 阅读(13) 评论(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 阅读(11) 评论(0) 推荐(0) 编辑
摘要:给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。 public class Solution { int max = 0; public int diameterOfBinaryTree(TreeNode root) 阅读全文
posted @ 2023-03-17 16:56 MarkLeeBYR 阅读(10) 评论(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 阅读(13) 评论(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 阅读(18) 评论(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 阅读(16) 评论(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 阅读(9) 评论(0) 推荐(0) 编辑
摘要:给定两个字符串 s 和 p,找到 s 中所有 p 的 异位词 的子串,返回这些子串的起始索引。不考虑答案输出的顺序。 异位词 指由相同字母重排列形成的字符串(包括相同的字符串)。 输入: s = "cbaebabacd", p = "abc"输出: [0,6]解释:起始索引等于 0 的子串是 "cb 阅读全文
posted @ 2023-03-16 17:58 MarkLeeBYR 阅读(16) 评论(0) 推荐(0) 编辑