题库chevron_right数组·string

数组·string 模式

49 道题目

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

识别信号

  • Do you understand how to handle edge cases like when there is no common prefix?
  • Can you describe the trade-offs between vertical scanning and horizontal scanning?
  • Able to explain space distribution in detail.

解题流程

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

常见失分点

  • Failing to handle the case where no common prefix exists, returning an empty string instead of a valid result.
  • Incorrectly distributing spaces when the number of spaces doesn't divide evenly.
  • Not using bitwise operations correctly, leading to inefficient comparisons or incorrect results.

推荐题单梯度

#题目难度
14

最长公共前缀

Find the longest common prefix in an array of strings, returning an empty string if none exists.

简单
68

文本左右对齐

Text Justification requires packing words into lines to match a specified width, ensuring even distribution of spaces.

困难
318

最大单词长度乘积

The problem requires finding the maximum product of lengths of two words from an array, where the words don't share comm…

中等
722

删除注释

Remove comments from a given C++ program source array, handling line and block comments.

中等
806

写字符串需要的行数

Calculate how many lines are needed to write a string given individual letter widths, constrained to 100 pixels per line…

简单
848

字母移位

Given a string and a shift array, shift the first i+1 letters of the string as specified in the array.

中等
937

重新排列日志文件

Reorder Data in Log Files requires sorting letter-logs lexicographically while keeping digit-logs in original order for …

中等
944

删列造序

The 'Delete Columns to Make Sorted' problem asks to remove unsorted columns from a string array, ensuring all columns ar…

简单
990

等式方程的可满足性

Determine if it's possible to assign values to variables such that all equations are satisfied based on equality and ine…

中等
1032

字符流

Implement a StreamChecker that detects if any suffix of a character stream matches a given list of words using efficient…

困难
1233

删除子文件夹

Remove sub-folders in a filesystem by filtering out folders nested inside other folders.

中等
1324

竖直打印单词

Transform a string into vertical columns by arranging each word character in array positions while trimming trailing spa…

中等
1408

数组中的字符串匹配

Identify all strings in an array that appear as substrings of other strings, focusing on array and string matching patte…

简单
1528

重新排列字符串

Reorder characters in a string using a given indices array to reconstruct the intended output efficiently and correctly.

简单
1629

按键持续时间最长的键

Determine which key had the longest press duration in a sequence using array indices and string mapping, resolving ties …

简单
1662

检查两个字符串数组是否相等

Determine if two string arrays form identical strings by concatenating elements in order, handling subtle array-length m…

简单
1769

移动所有球到每个盒子所需的最小操作数

Solve the problem of finding the minimum operations to move balls to each box using an efficient approach with arrays an…

中等
1773

统计匹配检索规则的物品数量

Count Items Matching a Rule is an easy problem that tests array and string manipulation with conditions based on specifi…

简单
1816

截断句子

Truncate a sentence to contain only the first k words by converting it into an array of words.

简单
1967

作为子字符串出现在单词中的字符串数目

Count how many strings in an array appear as substrings within a given word by checking each pattern individually.

简单
1985

找出数组中的第 K 大整数

This problem asks to find the kth largest integer in an array of string numbers, highlighting sorting and string-based c…

中等
2011

执行操作后的变量值

Compute the final value of X by simulating each string operation in the array sequentially with careful tracking.

简单
2114

句子中的最多单词数

Find the maximum number of words in a single sentence from an array of sentences using array and string processing techn…

简单
2185

统计包含给定前缀的字符串

Count how many words in a list start with a given prefix.

简单
2213

由单个字符重复的最长子字符串

Solve Longest Substring of One Repeating Character by maintaining mergeable run information under character updates afte…

困难
2255

统计是给定字符串前缀的字符串数目

Count Prefixes of a Given String is a problem that involves finding the number of string prefixes in an array that match…

简单
2343

裁剪数字后查询第 K 小的数字

Solve the Query Kth Smallest Trimmed Number problem by efficiently trimming and sorting strings in an array to answer qu…

中等
2381

字母移位 II

Shift letters in a string using a sequence of range-based forward or backward operations efficiently with prefix sums.

中等
2391

收集垃圾的最少总时间

This problem asks you to find the minimum amount of time needed to collect all garbage in a city, focusing on array and …

中等
2416

字符串的前缀分数和

The 'Sum of Prefix Scores of Strings' problem involves calculating prefix scores for strings based on their occurrences …

困难
2446

判断两个事件是否存在冲突

Compare two same-day time intervals and check whether their inclusive endpoints overlap after converting HH:MM strings i…

简单
2452

距离字典两次编辑以内的单词

Identify all words in queries that can match dictionary entries with at most two character changes efficiently using arr…

中等
2496

数组中字符串的最大值

The problem requires finding the maximum value of alphanumeric strings in an array based on length or numeric value.

简单
2515

到目标字符串的最短距离

Find the shortest distance to a target string in a circular array with either left or right movement options.

简单
2559

统计范围内的元音字符串数

Count the number of strings that start and end with a vowel in given ranges within an array of words.

中等
2586

统计范围内的元音字符串数

Count the Number of Vowel Strings in Range asks to count vowel strings in a subarray of a given word list.

简单
2678

老人的数目

Determine how many passengers are over 60 years old based on their compressed details in an array of strings.

简单
2788

按分隔符拆分字符串

Split Strings by Separator requires iterating through an array of strings and splitting each by a given separator charac…

简单
2828

判别首字母缩略词

Check if a string can be formed by concatenating the first letters of each word in a given list.

简单
2942

查找包含给定字符的单词

Identify all indices of words containing a specific character using array and string traversal techniques efficiently.

简单
2976

转换字符串的最小成本 I

This problem asks to calculate the minimum cost to convert a string from source to target using specific character trans…

中等
3042

统计前后缀下标对 I

Count all index pairs where one word is both a prefix and suffix of another, using efficient array and string checks.

简单
3045

统计前后缀下标对 II

Count the number of index pairs in a string array where one word is both a prefix and suffix of another using array and …

困难
3093

最长公共后缀查询

Find the index of the string in wordsContainer with the longest common suffix for each query efficiently using array and…

困难
3248

矩阵中的蛇

Solve the Snake in Matrix problem by simulating the snake's movement in a grid based on a series of directional commands…

简单
3361

两个字符串的切换距离

Find the minimum cost of transforming one string into another, considering operations between characters.

中等
3485

删除元素后 K 个字符串的最长公共前缀

Find the longest common prefix length of k strings after removing an element in the array.

困难
3529

统计水平子串和垂直子串重叠格子的数目

Efficiently count grid cells appearing in both horizontal and vertical occurrences of a given string pattern using array…

中等
3598

相邻字符串之间的最长公共前缀

Given an array of strings, find the longest common prefix length between adjacent strings after removals at each index.

中等

关联题型

LeetCode 数组·string模式题解:49题训练路线