题库chevron_right解题模式chevron_right贪心·invariant
schema可复用解题模式

贪心·invariant模式

模式页更适合建立可迁移的解题框架。先抓识别信号,再反复练状态定义、更新规则和边界解释,能比零散刷题更快形成稳定手感。

database198 道题tune37/128/33 难度梯度category6 个关联题型

模式摘要

先识别什么

题目里常出现可以复用的状态更新节奏。

解法节奏

先口述状态和不变量,再解释每一步如何更新,最后用反例验证边界。

高频失分点

状态定义说不清,写出来也难以稳定维护。

识别信号

  • 题目里常出现可以复用的状态更新节奏。
  • 暴力枚举太慢,但结构上存在可维护的不变量。
  • 面试追问通常会盯住边界、状态变更和复杂度。

解题流程

  1. 1. 明确窗口/状态定义
  2. 2. 更新状态并维护约束
  3. 3. 用边界样例验证

常见失分点

  • 状态定义说不清,写出来也难以稳定维护。
  • 只会背模板,解释不了为什么这样更新。
  • 样例能过,但边界和复杂度追问容易崩。

推荐题单梯度

题库

贪心·invariant模式题库

这里更适合先按关键词或难度找题,再按关联题型切入。题库会在容器内继续滚动时慢慢续载,避免模式页被长列表一下子拉穿。

慢加载模式题库

适合先建模式理解,再扩展到完整题单。

hourglass_bottom容器内滚动续载
search
tune难度
category题型聚焦

当前展示 24 / 198 道题目

每次续载 24 题
#题目难度
134

加油站

The Gas Station problem requires finding the starting station index for a full circular trip with gas stations and costs…

中等
135

分发糖果

The Candy problem is a greedy algorithm challenge where you need to minimize candy distribution while satisfying certain…

困难
179

最大数

The problem asks to arrange integers to form the largest possible number, focusing on greedy algorithms and string handl…

中等
324

摆动排序 II

Rearrange an array in a way that every odd-indexed element is greater than its adjacent even-indexed elements.

中等
330

按要求补齐数组

Patching Array requires adding the minimum numbers to cover all sums from 1 to n using greedy choices and invariant chec…

困难
334

递增的三元子序列

Identify if an array contains a strictly increasing triplet by maintaining a running minimal and middle value efficientl…

中等
409

最长回文串

Determine the length of the longest palindrome constructible from a given string using greedy counting and frequency tra…

简单
420

强密码检验器

The Strong Password Checker problem challenges you to optimize password strength while minimizing steps using greedy alg…

困难
452

用最少数量的箭引爆气球

Find the minimum number of arrows needed to burst all balloons by considering greedy choice and invariant validation.

中等
502

IPO

Maximize total capital by selecting up to k projects, based on initial capital and project profits using a greedy strate…

困难
517

超级洗衣机

Calculate the minimum moves to balance dresses across washing machines using a greedy strategy and invariant validation …

困难
561

数组拆分

Maximize the sum of minimums of n pairs in a 2n integer array using a greedy pairing strategy efficiently.

简单
605

种花问题

Determine if n new flowers can be planted in a flowerbed, ensuring no adjacent flowers using a greedy approach.

简单
624

数组列表中的最大距离

Maximum Distance in Arrays uses a greedy running minimum and maximum from previous arrays to validate cross array distan…

中等
630

课程表 III

Solve the 'Course Schedule III' problem with a greedy approach involving course selection and validation of constraints.

困难
670

最大交换

Given an integer, swap at most two digits once to produce the largest possible number using greedy digit selection.

中等
738

单调递增的数字

Determine the largest number less than or equal to n with digits in non-decreasing order using a greedy, invariant-drive…

中等
757

设置交集大小至少为2

Solve the Set Intersection Size At Least Two problem using a greedy approach and invariant validation.

困难
767

重构字符串

Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.

中等
807

保持城市天际线

Maximize building heights in a city grid without changing the skyline, using greedy selection constrained by row and col…

中等
857

雇佣 K 名工人的最低成本

Find the minimum cost to hire exactly k workers based on quality and wage expectations in this challenging greedy proble…

困难
860

柠檬水找零

Determine if you can provide exact change to every customer at a lemonade stand using greedy bill management techniques.

简单
861

翻转矩阵后的得分

Maximize the score of a binary matrix by flipping rows and columns using a greedy approach and validation of invariants.

中等
910

最小差值 II

Determine the minimum possible difference between the largest and smallest numbers after adjusting each by plus or minus…

中等

swap_vert在题库框内继续向下滚动,也会自动续载

按题型继续深入

模式学会之后,最好回到具体题型里做迁移训练。这样更容易分清楚“模式本身”和“场景变化”分别在哪里。

route

引导式练习路径

AI 会按你的当前水平推荐题目,并持续记录练习进度。

开始引导练习arrow_forward
LeetCode 贪心·invariant模式题解:198题训练路线