Avatar

Organizations

11 results for 贪心
  • 给定一个字符串  (s) 和一个字符模式  (p),实现一个支持  '?'  和  '*'  的通配符匹配。

    leetcode 困难 贪心 递归 字符串 Created Tue, 06 Dec 2022 14:03:07 +0800
  • 有一些球形气球贴在一堵用 XY 平面表示的墙面上。墙面上的气球记录在整数数组  points ,其中 \(points[i] = [x_{start}, x_{end}]\)  表示水平直径在  \(x*{start}\)  和 \(x*{end}\)之间的气球。你不知道气球的确切 y 坐标。

    一支弓箭可以沿着 x 轴从不同点 完全垂直 地射出。在坐标 x处射出一支箭,若有一个气球的直径的开始和结束坐标为 \(x*{start}\),\(x*{end}\), 且满足  \(x*{start} ≤ x ≤ x*{end}\),则该气球会被引爆。可以射出的弓箭的数量 没有限制 。弓箭一旦被射出之后,可以无限地前进。

    给你一个数组 points ,返回引爆所有气球所必须射出的 最小弓箭数。

    leetcode 中等 贪心 数组 排序 Created Fri, 02 Dec 2022 15:26:34 +0800
  • Given an array of intervals intervals where \(intervals[i] = [start_i, end_i]\), return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.

    leetcode 单推人 贪心 数组 动态规划 Created Sun, 26 Jun 2022 13:49:43 +0800
  • You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

    Find two lines that together with the x-axis form a container, such that the container contains the most water.

    Return the maximum amount of water a container can store.

    leetcode 中等 贪心 数组 双指针 Created Sun, 29 May 2022 14:00:35 +0800
  • Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens.

    You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the ith garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, which is the maximum number of flowers that Alice can additionally plant. You are also given the integers target, full, and partial.

    A garden is considered complete if it has at least target flowers. The total beauty of the gardens is then determined as the sum of the following:

    • The number of complete gardens multiplied by full.
    • The minimum number of flowers in any of the incomplete gardens multiplied by partial. If there are no incomplete gardens, then this value will be 0.

    Return the maximum total beauty that Alice can obtain after planting at most newFlowers flowers.

    leetcode 困难 前缀和 贪心 二分 Created Sun, 10 Apr 2022 12:20:00 +0800
  • A password is considered strong if the below conditions are all met:

    • It has at least 6 characters and at most 20 characters.
    • It contains at least one lowercase letter, at least one uppercase letter, and at least one digit.
    • It does not contain three repeating characters in a row (i.e., "...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).

    Given a string password, return the minimum number of steps required to make password strong. if password is already strong, return 0.

    In one step, you can:

    • Insert one character to password,
    • Delete one character from password, or
    • Replace one character of password with another character.
    leetcode 困难 贪心 字符串 Created Sat, 02 Apr 2022 13:21:16 +0800
  • 由于对计算机科学的热爱,以及有朝一日成为 「Bessie 博士」的诱惑,奶牛 Bessie 开始攻读计算机科学博士学位。

    经过一段时间的学术研究,她已经发表了 N 篇论文,并且她的第 i 篇论文得到了来自其他研究文献的 ci 次引用。

    Bessie 听说学术成就可以用 h 指数来衡量。

    h 指数等于使得研究员有至少 h 篇引用次数不少于 h 的论文的最大整数 h。

    例如,如果一名研究员有 4 篇论文,引用次数分别为 (1,100,2,3),则 h 指数为 2,然而若引用次数为 (1,100,3,3) 则 h 指数将会是 3。

    为了提升她的 h 指数,Bessie 计划写一篇综述,并引用一些她曾经写过的论文。

    由于页数限制,她至多可以在这篇综述中引用 L 篇论文,并且她只能引用每篇她的论文至多一次。

    请帮助 Bessie 求出在写完这篇综述后她可以达到的最大 h 指数。

    注意 Bessie 的导师可能会告知她纯粹为了提升 h 指数而写综述存在违反学术道德的嫌疑;我们不建议其他学者模仿 Bessie 的行为。

    acwing 简单 枚举 贪心 双指针 Created Thu, 17 Mar 2022 16:37:13 +0800
  • 给你数字 k ,请你返回和为  k  的斐波那契数字的最少数目,其中,每个斐波那契数字都可以被使用多次。

    斐波那契数字定义为:

    • \(F_1 = 1\)
    • \(F_2 = 1\)
    • \(F_n = F_{n-1} + F_{n-2}\), 其中 n > 2 。

    数据保证对于给定的 k ,一定能找到可行解。

    leetcode 中等 贪心 Created Thu, 03 Feb 2022 20:03:54 +0800
  • 你正在参加一个多角色游戏,每个角色都有两个主要属性:攻击防御 。给你一个二维整数数组 properties ,其中 \(properties[i] = [attack_i, defense_i]\) 表示游戏中第 i 个角色的属性。

    如果存在一个其他角色的攻击和防御等级 都严格高于 该角色的攻击和防御等级,则认为该角色为 弱角色 。更正式地,如果认为角色 i 弱于 存在的另一个角色 j ,那么 \(attack_j > attack_i\) 且 \(defense_j > defense_i\) 。

    返回 弱角色 的数量。

    leetcode 中等 贪心 数组 Created Fri, 28 Jan 2022 10:27:51 +0800
  • 农夫约翰将按字典序排列的 N 头奶牛的名字列表贴在了牛棚的门上。

    每个奶牛的名字都由一个长度介于 1 到 20 之间的由小写字母构成的唯一字符串表示。

    麻烦制造者贝茜将列表中的奶牛名字重新排序打乱了列表。

    此外,她还对每头奶牛的名字中的字母顺序进行了重新排列(也可能保持不变)。

    给定修改过后的列表,请帮助约翰确定列表中的每个名字可能出现在原始列表中的最低和最高位置。

    acwing 简单 贪心 二分 Created Sun, 09 Jan 2022 18:39:18 +0800
Next