题库chevron_right数组·数学

数组·数学 模式

111 道题目

模式页适合用来建立可复用解题框架。先识别题目特征,再按固定流程解释状态定义、转移和边界。

识别信号

  • Focus on in-place array manipulation rather than creating a new matrix.
  • Check if candidate uses both transpose and row reversal, showing understanding of index math.
  • Can the candidate handle the carry and array resizing efficiently?

解题流程

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

常见失分点

  • Trying to rotate using an extra matrix, which violates in-place constraint.
  • Forgetting to handle carry-over when incrementing digits.
  • Attempting to divide every number by all smaller numbers instead of using a sieve.

推荐题单梯度

#题目难度
48

旋转图像

Rotate an n x n matrix 90 degrees clockwise in-place using array manipulation and mathematical indexing techniques effic…

中等
66

加一

Given a number as an array of digits, increment it by one and return the updated array of digits.

简单
204

计数质数

Count all prime numbers less than a given integer n using efficient array and math-based enumeration techniques.

中等
335

路径交叉

Determine if a path defined by sequential distances on a 2D plane crosses itself using array and math reasoning.

困难
384

打乱数组

Shuffle an Array requires designing a class to randomly permute an integer array while ensuring all permutations are equ…

中等
453

最小操作次数使数组元素相等

Compute the fewest steps to make all elements equal by incrementing n-1 array items, applying array and math reasoning.

中等
462

最小操作次数使数组元素相等 II

Find the minimum moves to equalize all array elements using increments or decrements with array and math techniques.

中等
477

汉明距离总和

Calculate the total Hamming distance between all pairs in an integer array using efficient bit manipulation techniques.

中等
539

最小时间差

Calculate the smallest time difference between clock points using array manipulation and mathematical conversions effici…

中等
587

安装栅栏

Find the perimeter fence of a garden by determining the outermost trees in a set of given tree coordinates.

困难
598

区间加法 II

Range Addition II requires counting maximum values in a matrix after incremental operations using array and math reasoni…

简单
628

三个数的最大乘积

Find three numbers in an array whose product is the largest using sorting and careful handling of negative values.

简单
667

优美的排列 II

Construct a beautiful arrangement of integers from 1 to n with k distinct integers, optimizing for time and space effici…

中等
775

全局倒置与局部倒置

Determine if every global inversion in a permutation array is also a local inversion using array and math logic efficien…

中等
782

变为棋盘

Determine the minimum swaps of rows or columns to convert an n x n binary board into a valid chessboard configuration.

困难
789

逃脱阻碍者

Escape The Ghosts tests your ability to analyze movements in an infinite grid while racing against ghost positions using…

中等
810

黑板异或游戏

The Chalkboard XOR Game is a game theory problem involving array manipulation and bitwise XOR, where players alternate e…

困难
812

最大三角形面积

Find the area of the largest triangle formed by three distinct points on a 2D plane.

简单
843

猜猜这个单词

Master the Guess the Word problem by applying array manipulation, match-counting math, and strategic interactive guessin…

困难
883

三维形体投影面积

Calculate the projection area of a 3D shape defined by a grid of towers with varying heights.

简单
891

子序列宽度之和

Calculate the sum of widths for all subsequences in an integer array using sorting and combinatorial math efficiently.

困难
892

三维形体的表面积

Solve the Surface Area of 3D Shapes problem using array manipulation and mathematical formulas to calculate surface area…

简单
908

最小差值 I

Find the smallest score of an array after applying an operation to each element within a given range.

简单
927

三等分

Divide a binary array into three contiguous parts such that each part represents the same integer value in binary, using…

困难
932

漂亮数组

Beautiful Array builds a valid permutation by recursively separating odd and even positions so no middle-average triple …

中等
973

最接近原点的 K 个点

Find the k closest points to the origin in a 2D plane using array operations and Euclidean distance calculations efficie…

中等
989

数组形式的整数加法

Compute the sum of an integer and a number represented as an array, efficiently handling digit carries and array travers…

简单
1030

距离顺序排列矩阵单元格

Compute all matrix cell coordinates sorted by Manhattan distance from a given center using array and math techniques eff…

简单
1037

有效的回旋镖

Determine if three points on a 2D plane form a boomerang, based on distinctness and non-collinearity.

简单
1073

负二进制数相加

Add two numbers represented in negabinary format and return the result in the same format.

中等
1093

大样本统计

Calculate minimum, maximum, mean, median, and mode from a large sample represented by an array of counts.

中等
1131

绝对值表达式的最大值

Calculate the largest sum of absolute differences across two arrays and their indices using an efficient pattern-based a…

中等
1232

缀点成线

Determine if a series of coordinates form a straight line on a 2D plane using geometry and mathematical principles.

简单
1250

检查「好数组」

Determine if a given array of positive integers can generate 1 using integer multiples of any subset, leveraging number …

困难
1252

奇数值单元格的数目

This problem involves updating a matrix based on given indices and counting cells with odd values afterward.

简单
1266

访问所有点的最小时间

Calculate the minimum seconds required to visit all given 2D points in order using optimal diagonal or straight moves.

简单
1295

统计位数为偶数的数字

Count the integers in an array that have an even number of digits using a direct array traversal with digit math.

简单
1304

和为零的 N 个不同整数

Generate an array of n unique integers that sum to zero using a symmetric pairing strategy to ensure balance.

简单
1352

最后 K 个数的乘积

Design a data structure to efficiently return the product of the last k numbers in a dynamic integer stream using prefix…

中等
1390

四因数

Compute the sum of all divisors for numbers in an array that have exactly four divisors using array and math techniques.

中等
1453

圆形靶内的最大飞镖数量

Maximize the number of darts on a circular dartboard given dart positions and radius.

困难
1515

服务中心的最佳位置

Find the optimal service center position in a city by minimizing the sum of Euclidean distances to all customers.

困难
1588

所有奇数长度子数组的和

Calculate the sum of all odd-length subarrays in a given integer array using efficient array and math strategies.

简单
1627

带阈值的图连通性

In 'Graph Connectivity With Threshold,' determine if cities are connected based on common divisors exceeding a threshold…

困难
1685

有序数组中差绝对值之和

Calculate the sum of absolute differences between each element and others in a sorted array efficiently.

中等
1806

还原排列的最少操作步数

Find the minimum number of operations to reinitialize a permutation of size n using specific operations.

中等
1819

序列中不同最大公约数的数目

Given an array of positive integers, find the number of different subsequences' GCDs.

困难
1822

数组元素积的符号

Determine the sign of a product from an integer array using a single pass without computing the full product.

简单
1828

统计一个圆中点的数目

Determine how many 2D points lie within multiple circles using array iteration and Euclidean distance calculations effic…

中等
1835

所有数对按位与结果的异或和

Compute the XOR sum of all pairwise ANDs between two integer arrays using array and bitwise math techniques efficiently.

困难
1840

最高建筑高度

Find the maximum building height in a city given height restrictions for specific buildings.

困难
1878

矩阵中最大的三个菱形和

Find the three largest distinct rhombus sums from a given grid using array and math techniques.

中等
1979

找出数组的最大公约数

Find the greatest common divisor of the smallest and largest numbers in an integer array.

简单
1998

数组的最大公因数排序

The GCD Sort problem challenges you to sort an array using a specific gcd-based swap method.

困难
2028

找出缺失的观测数据

Given a set of dice rolls, calculate the missing observations based on the mean and return them or determine if it's imp…

中等
2033

获取单值网格的最小操作数

Determine the fewest additions or subtractions of x to make all grid elements identical using array and math logic.

中等
2125

银行中的激光束数量

Calculate total laser beams in a bank floor plan using array counting and math logic between security devices on differe…

中等
2183

统计可以被 K 整除的下标对数目

Count Array Pairs Divisible by K requires counting index pairs whose products are divisible by a given number k.

困难
2217

找到指定长度的回文数

Find the smallest palindromes of a given length for specific queries with mathematical and array manipulation.

中等
2221

数组的三角和

The problem asks for calculating the triangular sum of an array through repeated pairwise summation.

中等
2280

表示一个折线图的最少线段数

Determine the fewest lines needed to accurately connect stock price points in a line chart using array and math reasonin…

中等
2317

操作后的最大异或和

Maximize the bitwise XOR of an array after applying a special operation with non-negative integers multiple times.

中等
2344

使数组可以被整除的最少删除次数

Find the minimum number of deletions to make the smallest element in nums divide all elements of numsDivide.

困难
2348

全 0 子数组的数目

Given an array of integers, count the subarrays that consist entirely of 0s.

中等
2447

最大公因数等于 K 的子数组数目

Count the number of subarrays with GCD equal to a given value k from a list of integers.

中等
2455

可被三整除的偶数的平均值

Find the average of even numbers divisible by 3 from an array of positive integers.

简单
2470

最小公倍数等于 K 的子数组数目

Find the number of subarrays in an array where the least common multiple (LCM) of the subarray equals a given integer k.

中等
2527

查询数组异或美丽值

Find the xor-beauty of an array by XORing the effective values of all possible triplets of indices.

中等
2535

数组元素和与数字和的绝对差

Find the absolute difference between element sum and digit sum of an array of integers.

简单
2575

找出字符串的可整除数组

Calculate the divisibility array for a string by checking if prefixes are divisible by a given number.

中等
2614

对角线上的质数

Find the largest prime number located on any diagonal of a square matrix using array iteration and prime checking techni…

简单
2654

使数组所有元素变成 1 的最少操作次数

Find the minimum number of operations to transform every element of a positive integer array into 1 using gcd operations…

中等
2709

最大公约数遍历

Determine if every index in an array can be reached from any other using traversals based on greatest common divisors.

困难
2761

和等于目标值的质数对

Find all prime number pairs that sum up to a given integer n using an efficient sieve-based array approach.

中等
2862

完全子集的最大元素和

Given a 1-indexed array, select a subset where indices' product is a perfect square, then return the maximum sum.

困难
2946

循环移位后的矩阵相似检查

Determine if a matrix returns to its original state after performing cyclic row shifts k times using array and math patt…

简单
2954

统计感冒序列的数目

Calculate all valid infection sequences in a line by using array positions and combinatorial math efficiently for n peop…

困难
2961

双模幂运算

Solve the Double Modular Exponentiation problem by applying array manipulation and modular arithmetic to find good indic…

中等
3024

三角形类型

Determine the type of triangle from a three-element array using side sums and equality checks efficiently in constant ti…

简单
3025

人员站位的方案数 I

Calculate how many valid pairs of points can be formed on a 2D plane using array and math enumeration techniques efficie…

中等
3027

人员站位的方案数 II

Calculate all valid placements of people on a 2D grid ensuring Alice can fence herself with Bob without enclosing others…

困难
3047

求交集区域内的最大正方形面积

Find the largest square area that can fit inside the intersection of two or more rectangles in a 2D plane.

中等
3079

求出加密整数的和

Compute the sum of encrypted integers by replacing each digit with the largest digit, combining array traversal with dig…

简单
3101

交替子数组计数

Count all alternating subarrays in a binary array efficiently using array patterns and simple mathematical reasoning.

中等
3102

最小化曼哈顿距离

Compute the minimum maximum Manhattan distance by removing one point using array math and geometry insights efficiently.

困难
3115

质数的最大距离

Calculate the largest index gap between prime numbers in an array using array traversal and number theory insights effic…

中等
3179

K 秒后第 N 个元素的值

Solve for the N-th value after K seconds by simulating array updates and using prefix sum techniques.

中等
3190

使所有元素都可以被 3 整除的最少操作数

Find the minimum number of operations to make all elements in an array divisible by three.

简单
3232

判断是否可以赢得数字游戏

Determine if Alice can guarantee a win in a game by selectively summing single or double-digit numbers from an array.

简单
3233

统计不是特殊数字的数字数量

Count the numbers between two integers that are not special, where special numbers are squares of primes.

中等
3235

判断矩形的两个角落是否可达

Determine if there is a valid path from the bottom-left to top-right of a rectangle while avoiding circles.

困难
3264

K 次乘运算后的最终数组 I

Solve the problem of determining the final state of an array after multiple multiplication operations using a priority q…

简单
3283

吃掉所有兵需要的最多移动次数

Calculate the maximum number of moves to eliminate all pawns using BFS, bitmasking, and precise array position math effi…

困难
3300

替换为数位和以后的最小元素

Replace each number with its digit sum and return the smallest resulting value, using array plus math techniques efficie…

简单
3334

数组的最大因子得分

Calculate the maximum factor score of an integer array by optionally removing one element using LCM and GCD computations…

中等
3380

用点构造面积最大的矩形 I

Find the maximum area of a rectangle formed by given points on a plane with unique coordinates.

中等
3382

用点构造面积最大的矩形 II

Find the largest rectangle on a plane using given points while avoiding any interior points and optimizing with math and…

困难
3432

统计元素和差值为偶数的分区方案

Count the number of partitions with an even sum difference from an array of integers.

简单
3433

统计用户被提及情况

Calculate how many times each user is mentioned across MESSAGE events, accounting for offline and online statuses effici…

中等
3468

可行数组的数目

Find the number of possible arrays by leveraging bounds and math in this array-based problem.

中等
3470

全排列 IV

Find the k-th alternating permutation of numbers 1 to n, ensuring no adjacent numbers share parity, using array and math…

困难
3495

使数组元素都变为零的最少操作次数

Minimize operations to reduce array elements to zero, focusing on array manipulation, math, and bit operations for effic…

困难
3512

使数组和能被 K 整除的最少操作次数

This problem asks you to find the minimum operations to make the sum of an array divisible by a given integer k.

简单
3513

不同 XOR 三元组的数目 I

Calculate all unique XOR triplet values in a permutation array using array traversal and bit manipulation techniques eff…

中等
3514

不同 XOR 三元组的数目 II

Count all unique XOR results from triplets in an integer array using array traversal and bit manipulation techniques eff…

中等
3525

求出数组的 X 值 II

The "Find X Value of Array II" problem requires calculating the number of ways to remove a suffix from an array such tha…

困难
3550

数位和等于下标的最小下标

Find the smallest index in an array where the sum of the digits equals the index.

简单
3569

分割数组后不同质数的最大数目

Compute the maximum number of distinct prime numbers after sequentially updating array elements with efficient preproces…

困难
3574

最大子数组 GCD 分数

Maximize Subarray GCD Score focuses on maximizing a subarray's score by using at most k doubling operations on an array …

困难
3577

统计计算机解锁顺序排列数

Calculate the total valid unlocking sequences for computers based on their complexity using array and combinatorics logi…

中等
3618

根据质数下标分割数组

Split Array by Prime Indices challenges you to separate elements at prime positions and minimize the absolute sum differ…

中等

关联题型

LeetCode 数组·数学模式题解:111题训练路线