09 2022 档案
摘要:单调栈的定义与证明 前言 最近领悟到了单调栈的本质,特此来记录一下我的理解。 单调栈主要用来解决这样一类问题,当枚举到下标,要求在下标之前小于大于的数的下标中,找到最小最大的下标位置。 一共有四种不同的情况,下面来证明在这四种情况中,栈内维护的元素始终单调递增或单调
阅读全文
摘要:Find All Good Indices You are given a 0-indexed integer array nums of size and a positive integer . We call an index in the range $k \leq i
阅读全文
摘要:Longest Subarray With Maximum Bitwise AND You are given an integer array nums of size . Consider a non-empty subarray from nums that has the maximu
阅读全文
摘要:旅行 给定一个 个节点的树,节点编号为 。 请你从中选择一个简单路径(不能包含重复节点或重复的边),并沿所选路径来一场旅行,更具体的说,就是从所选路径的一个端点沿路径前往另一个端点。 注意,所选简单路径可以只由一个节点组成。 旅行需要花费能量。 初始时,你的能量为
阅读全文
摘要:减法操作 给定一个包含 个非负整数的数列 。 你可以对该数列进行以下两种减法操作: 任选其中一个元素,并将该元素的值减去 。 任选两个相邻元素,并将两个元素的值各减去 。 请你判断,能否经过一系列减法操作,使得数列中的所有元素都变为 $0
阅读全文
摘要:分成互质组 给定 个正整数,将它们分组,使得每组中任意两个数互质。 至少要分成多少个组? 输入格式 第一行是一个正整数 。 第二行是 个不大于 的正整数。 输出格式 一个正整数,即最少需要的组数。 数据范围 输入样例: 6
阅读全文
摘要:Sum of Prefix Scores of Strings You are given an array words of sizeco sisting of non-empty strings. We define the score of a string word as the n
阅读全文
摘要:Minimum Money Required Before Transactions You are given a 0-indexed 2D integer array transactions , where transactions[i] = [costi, cashbacki] . The
阅读全文
摘要:Smallest Subarrays With Maximum Bitwise OR You are given a 0-indexed array nums of length , consisting of non-negative integers. For each index
阅读全文
摘要:解方程 给定一个非负整数 ,请你计算方程 的非负整数解的数量。 其中 指按位异或。 输入格式 第一行包含整数 ,表示共有 组测试数据。 每组数据占一行,包含一个非负整数 。 输出格式 每组数据输出一行结果,一个整数
阅读全文
摘要:击中战舰 李华在玩一款叫做《海战》的小游戏,下面是游戏介绍。 给定一个 的方格矩阵,方格从左到右依次编号为 。 在这个方格矩阵中,隐藏着 个战舰。 每个战舰都占据 个连续的方格,每个方格最多只能被一个战舰占据。 每个战舰的具体位置未知。
阅读全文
摘要:最长上升子序列 给定一个长度为 的数列,求数值严格单调递增的子序列的长度最长是多少。 输入格式 第一行包含整数 。 第二行包含 个整数,表示完整序列。 输出格式 输出一个整数,表示最大长度。 数据范围 ,${−10}^{9} \leq \
阅读全文
摘要:原文链接: https://www.acwing.com/file_system/file/content/whole/index/content/6489818/ 想必很多同学在接触递归算法的时候都会很困惑,比如归并排序,为什么下面的代码可以将一个序列排好序呢? 今天突然发现,递归过程的本质就是数
阅读全文
摘要:Evaluate Division You are given an array of variable pairs equations and an array of real numbers values , where equations[i] = [Ai, Bi] and values[i]
阅读全文
摘要:Count Unique Characters of All Substrings of a Given String Let's define a function countUniqueChars(s) that returns the number of unique characters o
阅读全文
摘要:Meeting Rooms III You are given an integer . There are rooms numbered from to . You are given a 2D integer array meetings where meet
阅读全文
摘要:Number of Ways to Reach a Position After Exactly k Steps You are given two positive integers startPos and endPos . Initially, you are standing at posi
阅读全文
摘要:Maximum Number of Robots Within Budget You have robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts , both of length
阅读全文
摘要:列表排序 给定一个 行 列的整数列表。 列表中每一行的 个整数都是一个 的排列。 现在,你可以对该列表执行以下两种操作: 选择一行中的两个整数并交换它们。此操作,每行最多只能执行一次。 选择列表中的两列并交换它们。此操作,最多只能执行一次。 不难发现,你
阅读全文
摘要:环形石子合并 将 堆石子绕圆形操场排放,现要将石子有序地合并成一堆。 规定每次只能选相邻的两堆合并成新的一堆,并将新的一堆的石子数记做该次合并的得分。 请编写一个程序,读入堆数 及每堆的石子数,并进行如下计算: 选择一种合并石子的方案,使得做 次合并得分总和最大。 选择一
阅读全文