Avatar

Organizations

9 results for 前缀和
  • 给你一个整数数组 nums 和一个整数 k ,找出 nums 中和至少为 k最短非空子数组 ,并返回该子数组的长度。如果不存在这样的 子数组 ,返回 -1

    leetcode 困难 队列 数组 二分查找 Created Wed, 21 Dec 2022 21:15:00 +0800
  • 给你一个正整数数组 arr ,请你计算所有可能的奇数长度子数组的和。

    子数组 定义为原数组中的一个连续子序列。

    请你返回 arr 中 所有奇数长度子数组的和

    leetcode 简单 数组 数学 前缀和 Created Fri, 02 Dec 2022 14:13:41 +0800
  • 给定一个二进制数组 nums 和一个整数 k

    k 位翻转 就是从 nums 中选择一个长度为 k子数组,同时把子数组中的每一个 0 都改成 1 ,把子数组中的每一个 1 都改成0

    返回数组中不存在 0 所需的最小 k 位翻转次数。如果不可能,则返回  -1 。

    leetcode 困难 位运算 队列 数组 Created Mon, 19 Sep 2022 18:54:07 +0800
  • Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.

    A subarray is a contiguous non-empty sequence of elements within an array.

    leetcode 中等 数组 哈希表 前缀和 Created Mon, 27 Jun 2022 14:37:09 +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
  • 由于对计算机科学的热爱,以及有朝一日成为 「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
  • You are given an array nums. You can rotate it by a non-negative integer k so that the array becomes [nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]. Afterward, any entries that are less than or equal to their index are worth one point.

    • For example, if we have nums = [2,4,1,3,0], and we rotate by k = 2, it becomes [1,3,0,2,4]. This is worth 3 points because 1 > 0 [no points], 3 > 1 [no points], 0 <= 2 [one point], 2 <= 3 [one point], 4 <= 4 [one point].

    Return the rotation index k that corresponds to the highest score we can achieve if we rotated nums by it. If there are multiple answers, return the smallest such index k.

    leetcode 困难 数组 前缀和 Created Wed, 09 Mar 2022 14:47:26 +0800
  • 农夫约翰的 N 头奶牛站在一维长围栏的不同位置。

    第 i 头牛位于位置 xi,其所属品种为 bi(根西岛牛或荷斯坦牛)。

    所有奶牛的位置各不相同。

    约翰想给一段连续区间内的奶牛拍摄一张照片,用来在乡村集市上展览。

    但是我们希望他所有品种的奶牛都能在照片中得到公平的展示。

    因此,他希望确保无论照片中出些哪些品种的奶牛,每种品种的奶牛在照片中的数量都必须相等。

    例如,一张照片中只包含荷斯坦牛是可以的,包含荷斯坦牛和根西岛牛各 27 头也没问题,但是包含 10 头荷斯坦牛和 9 头根西岛牛则不可以。

    请确定,约翰可以拍下的满足以上条件的照片的最大尺寸。

    照片的尺寸是指照片中奶牛最大和最小位置之间的差。

    约翰最终可能只拍下一头奶牛,这种情况下,照片尺寸为 0。

    acwing 简单 枚举 前缀和 哈希表 Created Thu, 20 Jan 2022 12:57:54 +0800
  • 给你一个下标从 0 开始、由 n 个整数组成的数组 arr

    arr 中两个元素的 间隔 定义为它们下标之间的 绝对差 。更正式地,arr[i]arr[j] 之间的间隔是 |i - j|

    返回一个长度为 n 的数组  intervals ,其中 intervals[i]arr[i]arr 中每个相同元素(与 arr[i] 的值相同)的 间隔之和

    leetcode 中等 数组 哈希表 前缀和 Created Sun, 26 Dec 2021 15:11:10 +0800