题库chevron_rightstring driven

string driven 模式

58 道题目

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

识别信号

  • Watch for off-by-one errors in row traversal during zigzag simulation.
  • Check whether candidate handles single-row or short strings correctly.
  • Clarifies how whitespace and signs are handled before digit accumulation.

解题流程

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

常见失分点

  • Forgetting to reverse direction when reaching top or bottom row, breaking the zigzag pattern.
  • Failing to skip leading spaces before detecting the sign.
  • Attempting direct recursion without memoization can lead to stack overflow or repeated work.

推荐题单梯度

#题目难度
6

Z 字形变换

Convert a string into a zigzag pattern across multiple rows and read it line by line efficiently for string manipulation…

中等
8

字符串转换整数 (atoi)

Convert a string to a 32-bit signed integer by carefully parsing characters, handling signs, and ignoring invalid traili…

中等
38

外观数列

Count and Say requires building the nth sequence term by iteratively applying a run-length encoding on strings of digits…

中等
58

最后一个单词的长度

Determine the length of the last word in a string using a focused string-driven approach to handle spaces and trailing c…

简单
65

有效数字

Determine if a given string represents a valid number using precise string parsing and character validation rules.

困难
434

字符串中的单词数

Count the segments of non-space characters in a string by applying a string-driven approach to solve the problem.

简单
468

验证IP地址

Determine whether a given string is a valid IPv4 or IPv6 address using a precise string-driven validation strategy.

中等
482

密钥格式化

Reformat a license key string by splitting into groups of size k, converting to uppercase, and handling dashes appropria…

简单
520

检测大写字母

Detect Capital asks you to determine if a word follows a correct capital usage pattern based on specific rules.

简单
521

最长特殊序列 Ⅰ

Determine the length of the longest uncommon subsequence between two strings using a direct string comparison strategy.

简单
551

学生出勤记录 I

Determine if a student's attendance record qualifies for an award based on specific criteria for absences and lateness.

简单
709

转换成小写字母

The "To Lower Case" problem asks you to convert all uppercase letters in a string to lowercase.

简单
824

山羊拉丁文

Convert a sentence to Goat Latin by transforming each word based on vowel rules and incremental suffixes efficiently.

简单
830

较大分组的位置

Identify and return intervals of consecutive, large character groups in a string of lowercase letters.

简单
831

隐藏个人信息

This problem requires masking sensitive parts of emails and phone numbers using a precise string-driven strategy efficie…

中等
1078

Bigram 分词

Extract the third word in every adjacent triple of words matching a given bigram pattern from a text.

简单
1108

IP 地址无效化

Transform an IPv4 address by replacing each period with '[.]', focusing on a string-driven, direct manipulation approach…

简单
1309

解码字母到整数映射

Decrypt a string using alphabet-to-integer mapping, considering the presence of '#' as a special delimiter.

简单
1374

生成每种字符都是奇数个的字符串

Generate a string of n characters where each character appears an odd number of times, using a string-driven approach.

简单
1417

重新格式化字符串

Reformat The String involves rearranging alphanumeric characters in a string so that no adjacent characters have the sam…

简单
1446

连续字符

Find the power of a string by determining the length of its longest substring with a unique character.

简单
1507

转变日期格式

Reformat Date requires transforming a date string from human-readable form to YYYY-MM-DD using a string-driven strategy …

简单
1556

千位分隔数

Convert a given integer into a string with dots as thousand separators using a precise string-driven strategy.

简单
1576

替换所有的问号

Solve LeetCode 1576 by scanning left to right and replacing each ? with a letter different from its neighbors.

简单
1592

重新排列单词间的空格

Rearrange spaces between words by distributing them evenly, placing any leftover spaces at the end to match original tex…

简单
1678

设计 Goal 解析器

Interpret the Goal Parser's output by analyzing a command string containing 'G', '()', and '(al)' patterns.

简单
1694

重新格式化电话号码

Reformat a phone number by removing spaces and dashes, grouping digits into blocks of 3 or 2, and joining them with dash…

简单
1758

生成交替二进制字符串的最少操作数

Find the minimum number of changes required to convert a string into an alternating binary string.

简单
1784

检查二进制字符串字段

Check if a binary string contains at most one contiguous segment of ones.

简单
1844

将所有数字用字符替换

Transform a string by replacing digits at odd indices using the preceding character with a shift operation for accurate …

简单
1869

哪种连续子字符串更长

Determine if the longest segment of 1s in a binary string is strictly longer than the longest segment of 0s.

简单
1880

检查某单词是否等于两单词之和

Check if the sum of two word values equals a target word's value by converting letters to their numeric representations.

简单
1957

删除字符使字符串变好

This problem asks to remove the minimum number of characters from a string to ensure no three consecutive characters are…

简单
2042

检查句子中的数字是否递增

Check if the numbers in a sentence are strictly increasing from left to right using string tokenization.

简单
2047

句子中的有效单词数

Count all valid words in a sentence by analyzing each token with precise string-driven validation rules efficiently.

简单
2124

检查是否所有 A 都在 B 之前

Determine if all 'a's in a string appear before any 'b's using a direct string-driven check strategy for clarity and cor…

简单
2129

将标题首字母大写

Capitalize the Title requires transforming each word based on length, applying uppercase and lowercase rules precisely p…

简单
2194

Excel 表中某个范围内的单元格

This problem requires extracting a range of cells from an Excel-like sheet based on a string input and returning them in…

简单
2264

字符串中最大的 3 位相同数字

Find the largest 3-same-digit number within a string of digits using a string-driven solution approach.

简单
2278

字母在字符串中的百分比

Calculate the percentage of a specific letter in a string using a direct string-driven counting approach, rounding down …

简单
2288

价格减免

Apply Discount to Prices involves updating a sentence by applying a percentage discount to price words, with precise for…

中等
2299

强密码检验器 II

Check if a given password meets all strength requirements, including length, character types, and no adjacent repeated c…

简单
2315

统计星号

The 'Count Asterisks' problem asks you to count '*' excluding those between pairs of '|' in a string.

简单
2414

最长的字母序连续子字符串的长度

Find the length of the longest continuous alphabetical substring from a given string of lowercase letters.

中等
2490

回环句

Determine if a sentence is circular by verifying each word's last character matches the next word's first character effi…

简单
2609

最长平衡子字符串

Find the longest balanced substring of a binary string where zeroes precede ones and counts of each are equal.

简单
2710

移除字符串中的尾随零

Remove trailing zeros from a string representing a positive integer number.

简单
2839

判断通过操作能否让字符串相等 I

Determine if two strings can be made equal by repeatedly swapping characters at any two indices in each string.

简单
2914

使二进制字符串变美丽的最少修改次数

This problem involves determining the minimum number of changes to make a binary string beautiful using string-driven st…

中等
2937

使三个字符串相等

Determine the minimum number of operations to make three strings equal by removing rightmost characters from one string …

简单
3019

按键变更的次数

Count how many times a user switches keys in a typed string, ignoring shift and caps lock variations in characters.

简单
3110

字符串的分数

Calculate the sum of absolute ASCII differences between adjacent characters to score any given string efficiently.

简单
3136

有效单词

Determine if a given string qualifies as a valid word using a string-driven solution pattern with explicit character rul…

简单
3163

压缩字符串 III

Compress a string by repeatedly taking maximal same-character prefixes, following a string-driven solution strategy effi…

中等
3210

找出加密后的字符串

In this problem, you need to encrypt a string by shifting each character's position based on a given integer value.

简单
3330

找到初始输入字符串 I

Determine the length of the original string Alice intended to type by analyzing repeated characters and clumsy key press…

简单
3340

检查平衡字符串

Determine if a numeric string is balanced by comparing sums of digits at even and odd positions efficiently.

简单
3456

找出长度为 K 的特殊子字符串

Check efficiently if a string contains a consecutive sequence of length k where all characters match exactly one distinc…

简单

关联题型

LeetCode String-driven solution strategy模式题解:58题训练路线