leetcode.com 2023-09-30
🟡456.132-pattern
🏷️ Tags
#stack #array #binary_search #ordered_set #monotonic_stack
🟡456.132-pattern
🏷️ Tags
#stack #array #binary_search #ordered_set #monotonic_stack
Telegraph
132-pattern
Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise, return false. Example 1: Input:…
leetcode.cn 2023-10-02
🟡122.best-time-to-buy-and-sell-stock-ii
🏷️ Tags
#greedy #array #dynamic_programming
🟡122.best-time-to-buy-and-sell-stock-ii
🏷️ Tags
#greedy #array #dynamic_programming
Telegraph
best-time-to-buy-and-sell-stock-ii
给你一个整数数组 prices ,其中 prices[i] 表示某支股票第 i 天的价格。 在每一天,你可以决定是否购买和/或出售股票。你在任何时候 最多 只能持有 一股 股票。你也可以先购买,然后在 同一天 出售。 返回 你能获得的 最大 利润 。 示例 1: 输入:prices = [7,1,5,3,6,4] 输出:7 解释:在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。 随后,在第 4 天(股票价格…
leetcode.com 2023-10-02
🟡2038.remove-colored-pieces-if-both-neighbors-are-the-same-color
🏷️ Tags
#greedy #math #string #game_theory
🟡2038.remove-colored-pieces-if-both-neighbors-are-the-same-color
🏷️ Tags
#greedy #math #string #game_theory
Telegraph
remove-colored-pieces-if-both-neighbors-are-the-same-color
There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece. Alice and Bob are playing a game where they take alternating turns removing…
leetcode.cn 2023-10-05
🟡309.best-time-to-buy-and-sell-stock-with-cooldown
🏷️ Tags
#array #dynamic_programming
🟡309.best-time-to-buy-and-sell-stock-with-cooldown
🏷️ Tags
#array #dynamic_programming
Telegraph
best-time-to-buy-and-sell-stock-with-cooldown
给定一个整数数组prices,其中第 prices[i] 表示第 i 天的股票价格 。 设计一个算法计算出最大利润。在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票):
leetcode.cn 2023-10-06
🟡714.best-time-to-buy-and-sell-stock-with-transaction-fee
🏷️ Tags
#greedy #array #dynamic_programming
🟡714.best-time-to-buy-and-sell-stock-with-transaction-fee
🏷️ Tags
#greedy #array #dynamic_programming
Telegraph
best-time-to-buy-and-sell-stock-with-transaction-fee
给定一个整数数组 prices,其中 prices[i]表示第 i 天的股票价格 ;整数 fee 代表了交易股票的手续费用。 你可以无限次地完成交易,但是你每笔交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。 返回获得利润的最大值。 注意:这里的一笔交易指买入持有并卖出股票的整个过程,每笔交易你只需要为支付一次手续费。 示例 1: 输入:prices = [1, 3, 2, 8, 4, 9], fee = 2 输出:8 解释:能够达到的最大利润: 在此处买入 prices[0]…
leetcode.com 2023-10-07
🔴1420.build-array-where-you-can-find-the-maximum-exactly-k-comparisons
🏷️ Tags
#dynamic_programming #prefix_sum
🔴1420.build-array-where-you-can-find-the-maximum-exactly-k-comparisons
🏷️ Tags
#dynamic_programming #prefix_sum
Telegraph
build-array-where-you-can-find-the-maximum-exactly-k-comparisons
You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers: You should build the array arr which has the following properties:
leetcode.cn 2023-10-08
🟡2034.stock-price-fluctuation
🏷️ Tags
#design #hash_table #data_stream #ordered_set #heap_priority_queue
🟡2034.stock-price-fluctuation
🏷️ Tags
#design #hash_table #data_stream #ordered_set #heap_priority_queue
Telegraph
stock-price-fluctuation
给你一支股票价格的数据流。数据流中每一条记录包含一个 时间戳 和该时间点股票对应的 价格 。 不巧的是,由于股票市场内在的波动性,股票价格记录可能不是按时间顺序到来的。某些情况下,有的记录可能是错的。如果两个有相同时间戳的记录出现在数据流中,前一条记录视为错误记录,后出现的记录 更正 前一条错误的记录。 请你设计一个算法,实现: