JinFei's Blog

Thinking will not overcome fear but action will.

[LeetCode]121. Best Time to Buy and Sell Stock

dp,获取最大利润

题目描述 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of...

[LeetCode]31. 下一个排列

下一个排列

题目描述 实现获取 下一个排列 的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列(即,组合出下一个更大的整数)。 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列)。 必须 原地 修改,只允许使用额外常数空间。 Example 1: 输入:nums = [1,2,3] 输出:[1,3,2] Example 2: 输入:nums =...

[LeetCode]17. 电话号码的字母组合

字母组合

题目描述 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。 给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。 Example 1: 输入:digits = “23” 输出:[“ad”,”ae”,”af”,”bd”,”be”,”bf”,”cd”,”ce”,”cf”] Example 2: 输入:di...

[LeetCode]287. Find the Duplicate Number

STL使用

题目描述 Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate...

[LeetCode]371. Sum of Two Integers

不用加号做加法

题目描述 Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example1: Input: a = 1, b = 2 Output: 3 解题思路 普通做加法的过程 第一步,先算出 不进位的加法 用异...

[LeetCode]309. Best Time to Buy and Sell Stock with Cooldown

dp,求最大利润

题目描述 Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i...

[LeetCode]152. 乘积最大子数组

最大乘积数组

题目描述 给你一个整数数组 nums ,请你找出数组中乘积最大的连续子数组(该子数组中至少包含一个数字),并返回该子数组所对应的乘积。 Example 1: 输入: [2,3,-2,4] 输出: 6 解释: 子数组 [2,3] 有最大乘积 6。 Example 2: 输入: [-2,0,-1] 输出: 0 解释: 结果不能为 2, 因为 [-2,-1] 不是子数组。...

[LeetCode]55. 跳跃游戏

跳跃游戏

题目描述 给定一个非负整数数组 nums ,你最初位于数组的 第一个下标 。数组中的每个元素代表你在该位置可以跳跃的最大长度。判断你是否能够到达最后一个下标。 Example 1: 输入:nums = [2,3,1,1,4] 输出:true 解释:可以先跳 1 步,从下标 0 到达下标 1, 然后再从下标 1 跳 3 步到达最后一个下标。 Example 2: 输入...

[LeetCode]49. 字母异位词分组

异位词分组

题目描述 给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母都恰好只用一次。 Example 1: 输入: strs = [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”] 输出: [[“bat”],[“nat”,”tan”],[“ate”...

[LeetCode]39. 组合总和

指定和

题目描述 给定一个无重复元素的正整数数组 candidates 和一个正整数 target ,找出 candidates 中所有可以使数字和为目标数 target 的唯一组合。 candidates 中的数字可以无限制重复被选取。如果至少一个所选数字数量不同,则两种组合是唯一的。  对于给定的输入,保证和为 target 的唯一组合数少于 150 个。 Example 1: ...