
leecode刷题
白码思
Action! Action! Action!
Thinking! Thinking! Thinking!
Repeat above!
展开
-
【leetcode 刷题】 买卖股票的最佳时机含冷冻期
设计一个算法计算出最大利润。给定一个整数数组prices,其中第 prices[i] 表示第 i 天的股票价格。解释: 对应的交易状态为: [买入, 卖出, 冷冻期, 买入, 卖出]注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。卖出股票后,你无法在第二天买入股票 (即冷冻期为 1 天)。输入: prices = [1,2,3,0,2]输入: prices = [1]原创 2025-04-22 22:05:24 · 185 阅读 · 0 评论 -
【leetcode 刷题】 买卖股票的最佳时机 II
解释: 对应的交易状态为: [买入, 卖出, 冷冻期, 买入, 卖出]输入: prices = [1,2,3,0,2]动态规划, 主要是写出动态规划方程。输入: prices = [1]原创 2025-04-22 21:37:00 · 182 阅读 · 0 评论 -
[leetcode刷题算法总结] 回溯算法
下面给出一个常用的「回溯算法」C++ 代码示例,以及简要讲解。原创 2025-01-07 22:43:25 · 492 阅读 · 0 评论 -
leetcode刷题Valid Parentheses
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2019-06-14 10:34:12 · 219 阅读 · 0 评论 -
leetcode刷题atoi
class Solution {public: int myAtoi(string str) { int flag = 1; long result =0; int num = str.length(); int start = str.find_first_not_of(' '); if(sta...原创 2019-06-12 15:15:31 · 162 阅读 · 0 评论 -
leetcode Two Sum
Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-04-04 18:45:15 · 183 阅读 · 0 评论 -
leetcode第六题 recovertree 递归中序
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Example 1:Input: [1,3,null,null,2] 1 /3 \ 2Output: [3,1,null,...原创 2019-03-18 15:42:31 · 219 阅读 · 0 评论 -
leetcode第五题 sametree 深度搜索
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example ...原创 2019-03-18 13:57:59 · 160 阅读 · 0 评论 -
leetcode第四题(383. Ransom Note)
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot...原创 2018-11-07 17:02:55 · 286 阅读 · 0 评论 -
leetcode第三题35:search insert position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array....原创 2018-10-25 13:58:06 · 132 阅读 · 0 评论 -
leetcode第一题:滑雪问题
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 1...原创 2018-10-22 18:26:29 · 5221 阅读 · 0 评论