leetcode 45 ii

[LeetCode] 2300. Successful Pairs of Spells and Potions

You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell ......
Successful LeetCode Potions Spells Pairs

day18| 513.找树左下角的值;112.路径总和;113.路径总和II;106;105

513.找树左下角的值 深度优先搜索 class Solution: def findBottomLeftValue(self, root: Optional[TreeNode]) -> int: curVal = curHeight = 0 def dfs(node: Optional[TreeN ......
总和 路径 day 112 106

leetcode题中的逆向思维——集锦

417. 太平洋大西洋水流问题 虽然题目要求的是满足向下流能到达两个大洋的位置,如果我们对所有的位置进行搜索,那么在不剪枝的情况下复杂度会很高。因此我们可以反过来想,从两个大洋开始向上流,这样我们只需要对矩形四条边进行搜索。搜索完成后,只需遍历一遍矩阵,满足条件的位置即为两个大洋向上流都能到达的位置 ......
集锦 leetcode 思维

寒假每日一题——牛为什么过马路 II

牛为什么过马路 问题描述 农夫约翰的农场的布局十分奇特,一条大型的环形道路将奶牛吃草的田地围了起来。 每天早晨,奶牛们穿过这条道路,进入到田地吃草;每天晚上,奶牛们穿过这条道路,离开田地,返回牛棚休息。 众所周知,奶牛是有习性的动物,每头奶牛每天通过道路的方式都相同。 每头奶牛每天固定的从道路的某一 ......
马路 II

leetcode 394.字符串解码 Java

394.字符串解码 给定一个经过编码的字符串,返回它解码后的字符串。 编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次。注意 k 保证为正整数。 你可以认为输入字符串总是有效的;输入字符串中没有额外的空格,且输入的方括号总是符合格 ......
字符串 字符 leetcode Java 394

leetcode 739.每日的温度 Java

739.每日的温度 给定一个整数数组 temperatures ,表示每天的温度,返回一个数组 answer ,其中 answer[i] 是指对于第 i 天,下一个更高温度出现在几天后。如果气温在这之后都不会升高,请在该位置用 0 来代替。 示例 1: 输入: temperatures = [73, ......
leetcode 温度 Java 739

leetcode 20. 有效的括号 Java

给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。 每个右括号都有一个对应的相同类型的左括号。 示例 1: 输入:s = "()" 输出:true 示例 2: 输入 ......
括号 leetcode Java 20

Leetcode(剑指offer专项训练)——DP专项(6)

排序的数目 题目 给定一个由 不同 正整数组成的数组 nums ,和一个目标整数 target 。请从 nums 中找出并返回总和为 target 的元素组合的个数。数组中的数字可以在一次排列中出现任意次,但是顺序不同的序列被视作不同的组合。 题目数据保证答案符合 32 位整数范围。 链接 无效DF ......
专项 Leetcode offer

Leetcode(剑指offer专项训练)——DP专项(5)

最少的硬币数目 给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。 你可以认为每种硬币的数量是无限的。 链接 完全背包问题 思路:主要是要自己推出动态转移方程 $$ F(i)=min_{ ......
专项 Leetcode offer

面试题45(Java)-把数组排成最小的数(中等)

题目: 输入一个非负整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。 示例 1: 输入: [10,2] 输出: "102" 示例 2: 输入: [3,30,34,5,9] 输出: "3033459" 提示: 0 < nums.length <= 100 说明: 输出 ......
数组 Java 45

【DP】LeetCode 64. 最小路径和

题目链接 64. 最小路径和 思路 分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律 表示状态 假设到了右下角,考虑一下我们要存储的信息 走到最后坐标的最小步数 当前坐标的信息,用来判断是否走到了右下角 很容易联想到使用二维数组 dp[i][j ......
路径 LeetCode 64

【DP】LeetCode 70. 爬楼梯

题目链接 70. 爬楼梯 思路 分析动态规划题目的时候只需要考虑最后一个阶段,因为所有的阶段转化都是相同的,考虑最后一个阶段容易发现规律 表示状态 假设走到了最后一层台阶,考虑一下我们要存储的信息: 走到这最后一层台阶的方法数 当前台阶数,用于判断是否走到了最后一层台阶 这时候很容易想到使用一维数组 ......
楼梯 LeetCode 70

[LeetCode] 1338. Reduce Array Size to The Half 数组大小减半

You are given an integer array arr. You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum ......
数组 LeetCode 大小 Reduce Array

Leetcode(剑指offer专项训练)——DP专项(4)

加减的目标值 给定一个正整数数组 nums 和一个整数 target 。 向数组中的每个整数前添加 '+' 或 '-' ,然后串联起所有整数,可以构造一个 表达式 : 例如,nums = [2, 1] ,可以在 2 之前添加 '+' ,在 1 之前添加 '-' ,然后串联起来得到表达式 "+2-1" ......
专项 Leetcode offer

代码随想录Day17-Leetcode110.平衡二叉树,257. 二叉树的所有路径,404.左叶子之和

110.平衡二叉树 题目链接:https://leetcode.cn/problems/balanced-binary-tree/ 一个显然但似乎不太高效的方法是: 通过递归获取左右子树高度,判断差; 然后递归判断左右结点; 那么一个显然的改进就是后序遍历 /** * Definition for ......
随想录 之和 随想 路径 Leetcode

IIS Log(IIS日志)

IIS Log Window系统日志 任务管理器 IIS Log IIS Log开启 选择字段 添加自定义字段 日志分析 分析工具 Excel HttpLogBrowser Log Parser Log Parser Studio ......
IIS 日志 Log

LeetCode 85. Maximal Rectangle

class Solution { public: int method(vector<int> h)//求柱状图中最大的矩形 { int n=h.size(); vector<int> l=vector<int> (n),r=l; stack<int> st; //预处理l,r数组 for(int ......
Rectangle LeetCode Maximal 85

代码随想录day 32● 122.买卖股票的最佳时机II ● 55. 跳跃游戏 ● 45.跳跃游戏II

122.买卖股票的最佳时机II 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。 注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。 示例 1: 输入: [7,1,5,3,6 ......
随想录 随想 时机 代码 股票

day32 打卡122.买卖股票的最佳时机II 55. 跳跃游戏 45.跳跃游戏II

day32 打卡122.买卖股票的最佳时机II 55. 跳跃游戏 45.跳跃游戏II 122.买卖股票的最佳时机II 122题目链接 class Solution { public int maxProfit(int[] prices) { int result = 0 ; for (int i = ......
时机 股票 day 122 32

leetcode876. 链表的中间结点

876. 链表的中间结点 方法一: 最简单的做法,先求出整个链表的长度,再求1/2处节点的位置。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode( ......
结点 leetcode 876

Leetcode Practice --- 栈和队列

155. 最小栈 设计一个支持 push ,pop ,top 操作,并能在常数时间内检索到最小元素的栈。 实现 MinStack 类: MinStack() 初始化堆栈对象。 void push(int val) 将元素val推入堆栈。 void pop() 删除堆栈顶部的元素。 int top() ......
队列 Leetcode Practice

leetcode-733-easy

Flood Fill An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image. You are also given three ......
leetcode easy 733

leetcode-1005-easy

Maximize Sum Of Array After K Negations Given an integer array nums and an integer k, modify the array in the following way: choose an index i and rep ......
leetcode 1005 easy

leetcode-724-easy

Find Pivot Index Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbe ......
leetcode easy 724

leetcode-762-easy

Prime Number of Set Bits in Binary Representation Given two integers left and right, return the count of numbers in the inclusive range [left, right] ......
leetcode easy 762

leetcode-744-easy

Find Smallest Letter Greater Than Target You are given an array of characters letters that is sorted in non-decreasing order, and a character target. ......
leetcode easy 744

最长上升子序列 II

最长上升子序列 II 题目描述 给定一个长度为 N 的数列,求数值严格单调递增的子序列的长度最长是多少。 输入格式 第一行包含整数 N。 第二行包含 N 个整数,表示完整序列。 输出格式 输出一个整数,表示最大长度。 数据范围 1 ≤ N ≤100000 -10^9 ≤ 数列中的数 ≤ 10^9 输 ......
序列 II

LeetCode 100 相同的树

LeetCode | 100.相同的树 给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 示例 1: 输入:p = [1,2,3], q = [1,2,3] 输出:true 示例 2: 输入:p = [1, ......
LeetCode 100

LeetCode 94 二叉树的中序遍历

LeetCode | 94.二叉树的中序遍历 给定一个二叉树的根节点 root ,返回 它的 中序 遍历 。 示例 1: 输入:root = [1,null,2,3] 输出:[1,3,2] 示例 2: 输入:root = [] 输出:[] 示例 3: 输入:root = [1] 输出:[1] 提示: ......
LeetCode 94

树(层序遍历):剑指 Offer 32 - II. 从上到下打印二叉树 II

题目描述: 从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行。 例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层次遍历结果: [ [3], [9,20], [15,7]] 提示: 节点总数 <= 1000 ......
Offer II 32