题库chevron_right分类chevron_right双指针
compare_arrows

双指针

182 道题目
简单: 54中等: 104困难: 24

双指针 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
5

最长回文子串

Find the longest contiguous palindromic substring in a given string using dynamic programming and two-pointer expansion …

中等
11

盛最多水的容器

Find two vertical lines that can form a container with the most water in a given array of heights.

中等
15

三数之和

Given an integer array, return all unique triplets where the sum is zero using two-pointer scanning with careful duplica…

中等
16

最接近的三数之和

Find the sum of three integers in an array that is closest to a given target using two-pointer scanning.

中等
18

四数之和

The 4Sum problem requires finding all unique quadruplets in an array that sum to a specific target value.

中等
19

删除链表的倒数第 N 个结点

Remove the nth node from the end of a linked list using a two-pointer approach to solve efficiently.

中等
26

删除有序数组中的重复项

Learn how to remove duplicates from a sorted array in-place using two-pointer scanning while preserving element order.

简单
27

移除元素

Remove Element challenges you to remove a value from an array in-place using efficient two-pointer scanning and tracking…

简单
28

找出字符串中第一个匹配项的下标

Locate the first occurrence of a substring within a string using a two-pointer scanning strategy and invariant tracking …

简单
31

下一个排列

Next Permutation is a medium-difficulty problem focusing on generating the next lexicographically greater permutation of…

中等
42

接雨水

Calculate the total trapped rain water using the elevation map array, leveraging dynamic programming and two-pointer pat…

困难
61

旋转链表

Rotate a singly linked list to the right by k positions using careful pointer manipulation and two-pointer traversal tec…

中等
75

颜色分类

Sort Colors requires in-place reordering of an array using a two-pointer scanning strategy to group 0s, 1s, and 2s effic…

中等
80

删除有序数组中的重复项 II

Solve the problem of removing duplicates from a sorted array in-place, ensuring each element appears at most twice, usin…

中等
82

删除排序链表中的重复元素 II

Remove duplicates from a sorted linked list, leaving only distinct values, and return the modified list in sorted order.

中等
86

分隔链表

Partition a linked list such that all nodes less than x come before nodes greater than or equal to x while preserving re…

中等
88

合并两个有序数组

Merge two sorted arrays into the first array in non-decreasing order, using a two-pointer approach.

简单
125

验证回文串

Check if a given string is a valid palindrome by using two-pointer scanning and invariant tracking techniques.

简单
141

环形链表

Determine if a given linked list contains a cycle using pointer manipulation or hashing, focusing on detecting repeated …

简单
142

环形链表 II

Identify the start of a cycle in a linked list using pointer manipulation, efficiently handling edge cases without modif…

中等
143

重排链表

Reorder List requires careful pointer manipulation in a singly linked list to interleave nodes from the ends without alt…

中等
148

排序链表

Sort List requires sorting a singly linked list efficiently using pointer manipulation and merge sort for optimal perfor…

中等
151

反转字符串中的单词

Reverse Words in a String requires reordering words using precise two-pointer scanning with careful space handling for e…

中等
160

相交链表

Given two linked lists, find the node where they intersect or return null if they do not.

简单
165

比较版本号

Compare two version numbers by checking their individual revisions, considering missing revisions as zero, using a two-p…

中等
167

两数之和 II - 输入有序数组

Solve the Two Sum II problem efficiently using binary search over a valid answer space in a sorted array.

中等
189

轮转数组

Rotate Array challenges you to shift elements right by k steps using precise two-pointer scanning and invariant tracking…

中等
202

快乐数

Determine if a number is happy by repeatedly summing squares of digits using two-pointer scanning to detect cycles effic…

简单
234

回文链表

Solve Palindrome Linked List by finding the midpoint, reversing the second half, and comparing mirrored nodes in linear …

简单
283

移动零

Move all zeros in an array to the end while preserving the order of non-zero elements using efficient in-place operation…

简单
287

寻找重复数

The problem involves finding the duplicate number in an array of integers, using a binary search approach over the valid…

中等
295

数据流的中位数

Implement a MedianFinder class that supports adding numbers and finding the median from a data stream.

困难
321

拼接最大数

Create Maximum Number involves merging digits from two arrays while preserving order, maximizing the resulting number.

困难
344

反转字符串

Reverse a character array in-place using a two-pointer scanning technique, ensuring minimal memory and correct index swa…

简单
345

反转字符串中的元音字母

Reverse Vowels of a String uses a two-pointer approach to reverse the vowels in a string while leaving the consonants in…

简单
349

两个数组的交集

Find the intersection of two arrays while ensuring unique elements using efficient array scanning and hash lookups.

简单
350

两个数组的交集 II

Find the intersection of two arrays, accounting for multiple occurrences of the same number.

简单
392

判断子序列

Determine if one string is a subsequence of another using state transition dynamic programming for accurate character ma…

简单
443

压缩字符串

Compress a character array in-place by converting consecutive repeated characters into counts using two-pointer scanning…

中等
455

分发饼干

Maximize content children by assigning at most one cookie per child using two-pointer scanning and greedy sorting techni…

简单
457

环形数组是否存在循环

Detect whether a circular array contains a loop of consistent direction using efficient array scanning and hash lookup t…

中等
475

供暖器

Determine the minimum heater radius to cover all houses using a binary search over potential radius values efficiently.

中等
481

神奇字符串

Count the number of '1's in the first n characters of a magical string using two-pointer scanning and invariant tracking…

中等
522

最长特殊序列 II

Find the longest string in an array that is not a subsequence of any other string, using array scanning and hash checks …

中等
524

通过删除字母匹配到字典里最长单词

Find the longest word in the dictionary that can be formed by deleting characters from a string, using two-pointer scann…

中等
532

数组中的 k-diff 数对

Solve K-diff Pairs in an Array by counting unique differences with a hash map or sorted two-pointer sweep.

中等
541

反转字符串 II

Reverse String II requires reversing segments of a string using two-pointer scanning while tracking invariants carefully…

简单
556

下一个更大元素 III

Find the next greater integer using the same digits as a given number with precise two-pointer scanning and invariant tr…

中等
557

反转字符串中的单词 III

Reverse Words in a String III involves reversing each word in a sentence using the two-pointer technique.

简单
567

字符串的排列

Check if a string contains a permutation of another string using two-pointer scanning and hash table techniques.

中等
581

最短无序连续子数组

Find the shortest unsorted continuous subarray that, if sorted, would sort the entire array.

中等
611

有效三角形的个数

Count all triplets in an integer array that satisfy the triangle inequality to form valid triangles efficiently using so…

中等
633

平方数之和

Given a non-negative integer c, determine if there are two integers whose squares sum to c.

中等
647

回文子串

Count all palindromic substrings in a given string using state transition dynamic programming for efficient evaluation.

中等
653

两数之和 IV - 输入二叉搜索树

Determine if a binary search tree contains two nodes whose values sum to a target using efficient traversal and state tr…

简单
658

找到 K 个最接近的元素

Identify the k integers closest to a target x in a sorted array using binary search and two-pointer strategies efficient…

中等
680

验证回文串 II

Check if a string can become a palindrome by deleting at most one character using two-pointer scanning and invariant tra…

简单
696

计数二进制子串

Count Binary Substrings solves for the number of valid substrings with equal 0's and 1's, grouped consecutively in a bin…

简单
719

找出第 K 小的数对距离

Solve Find K-th Smallest Pair Distance by sorting nums, then binary searching the distance and counting valid pairs with…

困难
763

划分字母区间

Partition a string into maximal parts so that each letter appears in only one segment, using two-pointer scanning.

中等
777

在 LR 字符串中交换相邻字符

Transform one string into another by swapping adjacent 'L' and 'R' characters in a sequence of moves.

中等
786

第 K 个最小的质数分数

Find the k-th smallest fraction from a sorted array of unique primes using a binary search over the answer space.

中等
795

区间子数组个数

Count the number of contiguous subarrays with a bounded maximum value using a two-pointer approach.

中等
809

情感丰富的文字

Expressive Words challenges you to determine if a word can be transformed into a given string by extending groups of rep…

中等
821

字符的最短距离

Compute the minimum distance from each character in a string to a target character using efficient scanning techniques.

简单
825

适龄的朋友

The Friends Of Appropriate Ages problem involves counting valid friend requests between people based on their ages with …

中等
826

安排工作以达到最大收益

Assign workers to jobs maximizing total profit using difficulty, profit, and worker arrays efficiently with binary searc…

中等
832

翻转图像

Flip each row of a binary matrix horizontally and invert its values efficiently using a two-pointer scanning approach.

简单
838

推多米诺

In the "Push Dominoes" problem, you simulate the falling dominoes based on their initial states and determine their fina…

中等
844

比较含退格的字符串

Compare two strings after processing backspaces using efficient two-pointer scanning and careful invariant tracking to e…

简单
845

数组中的最长山脉

Find the length of the longest subarray forming a mountain pattern using state transitions and two-pointer logic efficie…

中等
870

优势洗牌

Maximize the advantage of nums1 over nums2 using a two-pointer greedy strategy, carefully tracking which elements beat o…

中等
876

链表的中间结点

Find the middle node of a singly linked list using a two-pointer technique.

简单
881

救生艇

Find the minimum number of boats required to save all people, using a two-pointer approach for efficient pairing.

中等
905

按奇偶排序数组

Reorder an integer array so all even numbers come before odd numbers using a precise two-pointer scanning method.

简单
917

仅仅反转字母

Reverse the characters of a string while skipping non-letter characters using a two-pointer technique.

简单
922

按奇偶排序数组 II

Sort an array where even numbers appear at even indices and odd numbers appear at odd indices using two-pointer scanning…

简单
923

三数之和的多种可能

Count all unique triplets in an integer array whose sum equals the target, handling multiplicity efficiently using hashi…

中等
925

长按键入

Check if a typed string could result from long pressing characters while typing a given name using a two-pointer scan.

简单
942

增减字符串匹配

Reconstruct a permutation from a DI string using two-pointer scanning, carefully tracking the increasing and decreasing …

简单
948

令牌放置

Maximize your score in the Bag of Tokens problem by strategically playing tokens with two-pointer scanning and greedy te…

中等
962

最大宽度坡

Find the maximum width of a ramp where nums[i] <= nums[j] for i < j using a two-pointer approach.

中等
969

煎饼排序

Sort an array using pancake flips, leveraging two-pointer scanning and invariant tracking to iteratively position the la…

中等
977

有序数组的平方

The problem involves squaring elements of a sorted array and returning the squares in non-decreasing order.

简单
986

区间列表的交集

This problem requires finding the intersection of two lists of intervals using a two-pointer technique with invariant tr…

中等
1023

驼峰式匹配

Camelcase Matching is a medium difficulty problem where you match queries to a given pattern by inserting lowercase lett…

中等
1048

最长字符串链

Find the longest word chain by scanning arrays and using hash lookups to efficiently track predecessor-successor sequenc…

中等
1089

复写零

Duplicate each zero in a fixed-length array in place, shifting elements right using a two-pointer scanning approach effi…

简单
1147

段式回文

Solve the "Longest Chunked Palindrome Decomposition" problem by using dynamic programming and string manipulation techni…

困难
1163

按字典序排在最后的子串

Identify the lexicographically last substring in a string using two-pointer scanning with invariant tracking efficiently…

困难
1237

找出给定方程的正整数解

Determine all positive integer pairs that satisfy a hidden monotonic function for a given target using binary search ove…

中等
1332

删除回文子序列

This problem challenges you to remove palindromic subsequences from a string with a minimum number of steps using two-po…

简单
1346

检查整数及其两倍数是否存在

Solve Check If N and Its Double Exist by scanning once and checking doubles or halves in a hash set.

简单
1385

两个数组间的距离值

Calculate the distance value between two integer arrays by determining how many elements in arr1 don't have a close coun…

简单
1455

检查单词是否为句中其他单词的前缀

Determine the first word in a sentence where a given searchWord is a prefix using two-pointer scanning with string match…

简单
1471

数组中的 k 个最强值

Identify the k strongest values in an array using two-pointer scanning and careful tracking of the array's centre value.

中等
1498

满足条件的子序列数目

Count all non-empty subsequences in an integer array where the sum of the minimum and maximum elements is at most a targ…

中等
1508

子数组和排序后的区间和

Compute the sum of sorted subarray sums efficiently using binary search over valid sum ranges and prefix sum accumulatio…

中等
1537

最大得分

Find the maximum possible score from two sorted arrays with a dynamic programming approach, leveraging partitioning and …

困难
1574

删除最短的子数组使剩余数组有序

Find the shortest subarray to remove in order to make an array non-decreasing using binary search and two-pointer techni…

中等
1577

数的平方等于两数乘积的方法数

Find the number of triplets where the square of a number equals the product of two others, utilizing array scanning and …

中等
1616

分割两个字符串得到回文串

Determine if splitting two equal-length strings at a common index can form a palindrome using two-pointer scanning techn…

中等
1679

K 和数对的最大数目

Max Number of K-Sum Pairs is a problem involving counting disjoint pairs with a given sum k in an array.

中等
1697

检查边长度限制的路径是否存在

Solve the problem of checking if there exists a path between two nodes under edge length constraints using efficient tec…

困难
1712

将数组分成三个子数组的方案数

The problem requires finding the number of ways to split an array into three subarrays where each split meets a certain …

中等
1721

交换链表中的节点

Swap nodes in a linked list using linked-list pointer manipulation and two pointers to solve this medium difficulty prob…

中等
1750

删除字符串两端相同字符后的最短长度

Minimize string length by deleting similar characters from both ends repeatedly using a two-pointer technique.

中等
1754

构造字典序最大的合并字符串

Construct the lexicographically largest merge from two strings using a two-pointer greedy scanning approach efficiently.

中等
1755

最接近目标值的子序列和

Find the minimum absolute difference between a target goal and any subsequence sum using optimized dynamic programming a…

困难
1764

通过连接另一个数组的子数组得到一个数组

Determine if you can sequentially select disjoint subarrays from nums matching each group in order using two-pointer sca…

中等
1768

交替合并字符串

Merge two strings alternately, starting with the first string, and append extra characters when one string is longer.

简单
1782

统计点对的数目

Given a graph with nodes and edges, count pairs of nodes where the degree sum exceeds a given threshold for each query.

困难
1793

好子数组的最大分数

Maximize the score of a good subarray using binary search to explore the valid answer space with a focus on two-pointer …

困难
1813

句子相似性 III

Sentence Similarity III asks if one sentence can be transformed into another by inserting a sentence inside it.

中等
1850

邻位交换的最小次数

Find the minimum number of adjacent swaps to reach the kth smallest wonderful integer from a given number string.

中等
1855

下标对中的最大距离

Find the maximum distance between a pair of values in two non-increasing integer arrays using binary search.

中等
1861

旋转盒子

Rotate a box represented by a character matrix, letting stones fall under gravity using precise two-pointer scanning and…

中等
1877

数组中最大数对和的最小值

Minimize the maximum pair sum in an array by optimally pairing its elements.

中等
1898

可移除字符的最大数目

Use binary search and a subsequence check to find the largest removable prefix that still keeps p inside s.

中等
1961

检查字符串是否为数组前缀

Determine if a string is a prefix of an array by concatenating initial elements, using two-pointer scanning efficiently.

简单
1963

使字符串平衡的最小交换次数

Determine the minimum swaps to balance a bracket string using two-pointer scanning with invariant tracking efficiently.

中等
2000

反转单词前缀

Reverse the prefix of a string starting from index 0 to the first occurrence of a given character.

简单
2035

将数组分成两个数组并最小化数组和的差

Partition an integer array into two equal halves to minimize the absolute difference of their sums using dynamic program…

困难
2071

你可以安排的最多任务数目

Maximize the number of tasks that can be completed by efficiently using workers and magical pills.

困难
2095

删除链表的中间节点

Efficiently remove the middle node from a linked list using two-pointer techniques and careful pointer updates to mainta…

中等
2105

给植物浇水 II

Simulate watering a row of plants with Alice and Bob using two-pointer scanning, tracking refills precisely for each ste…

中等
2108

找出数组中的第一个回文字符串

Return the first palindromic string from an array of words or an empty string if none exists.

简单
2109

向字符串添加空格

Learn to efficiently insert spaces in a string using two-pointer scanning with invariant tracking in linear time.

中等
2122

还原原数组

Recover the Original Array helps you understand how to reverse-engineer an array from two subsets using array scanning a…

困难
2130

链表最大孪生和

Find the maximum twin sum in a linked list by manipulating pointers efficiently and leveraging stack or reversal techniq…

中等
2149

按符号重排数组

Rearrange an array by alternating positive and negative integers using a two-pointer approach with invariant tracking.

中等
2161

根据给定数字划分数组

Rearrange an array around a pivot while maintaining relative order using a two-pointer scanning approach efficiently.

中等
2193

得到回文串的最少操作次数

The problem challenges you to find the minimum number of adjacent swaps to make a string a palindrome.

困难
2200

找出数组中的所有 K 近邻下标

Identify all indices in an array that are within k distance of elements equal to the given key using two-pointer scannin…

简单
2234

花园的最大总美丽值

Determine the maximum total beauty of gardens by strategically planting flowers using binary search over achievable flow…

困难
2300

咒语和药水的成功对数

Count how many potions pair successfully with each spell using binary search over sorted potion strengths efficiently.

中等
2332

坐上公交的最晚时间

Find the latest time to catch a bus based on departure times, passenger arrivals, and capacity using binary search over …

中等
2337

移动片段得到字符串

Determine if the pieces in start can be moved to form target using two-pointer scanning and strict left-right movement r…

中等
2367

等差三元组的数目

Count the number of arithmetic triplets in a given strictly increasing array with a specified difference.

简单
2396

严格回文的数字

Determine if a number is strictly palindromic in all bases from 2 to n minus 2 using two-pointer scanning and invariant …

中等
2406

将区间分为最少组数

Determine the minimum number of non-overlapping groups for a set of intervals using precise two-pointer scanning logic.

中等
2410

运动员和训练师的最大匹配数

Maximize the number of valid player-trainer matchings using two-pointer scanning and careful sorting strategy.

中等
2441

与对应负数同时存在的最大正整数

Find the largest positive integer in an array such that its negative counterpart also exists.

简单
2460

对数组执行操作

Transform an array by applying adjacent doubling operations and shifting zeros efficiently using two-pointer scanning te…

简单
2462

雇佣 K 位工人的总代价

Optimize the total cost of hiring exactly k workers using a two-pointer approach with invariant tracking and priority qu…

中等
2465

不同的平均值数目

Calculate the number of unique averages formed by repeatedly pairing smallest and largest elements efficiently using has…

简单
2472

不重叠回文子字符串的最大数目

Find the maximum number of non-overlapping palindromic substrings of at least length k in a string using dynamic program…

困难
2486

追加字符以获得子序列

Determine the minimum characters to append to s so t becomes a subsequence using efficient two-pointer scanning techniqu…

中等
2491

划分技能点相等的团队

Divide players into equal skill teams and return the sum of their chemistry, or -1 if impossible.

中等
2503

矩阵查询可获得的最大分数

Solve the Maximum Number of Points From Grid Queries problem using two-pointer scanning and invariant tracking.

困难
2511

最多可以摧毁的敌人城堡数目

Find the maximum number of enemy forts that can be captured by moving your army using two-pointer scanning with invarian…

简单
2540

最小公共值

Find the smallest integer appearing in both sorted arrays efficiently using array scanning and hash-based lookup techniq…

简单
2562

找出数组的串联值

Compute the array concatenation value efficiently using two-pointer scanning while maintaining a running total of concat…

简单
2563

统计公平数对的数目

Efficiently count all fair pairs in an array using sorting and binary search, focusing on the sum range between lower an…

中等
2565

最少得分子序列

Find the minimum score of a string by removing characters from t while maintaining subsequence validity with s.

困难
2570

合并两个二维数组 - 求和法

Merge two 2D arrays by summing values with matching ids using array scanning and hash lookup efficiently.

简单
2576

求出最多标记下标

Maximize marked indices in an array by performing allowed operations, applying binary search to find the optimal count e…

中等
2592

最大化数组的伟大值

Maximize Greatness of an Array requires permuting numbers to exceed original values at most indices efficiently.

中等
2697

字典序最小回文串

Given a string, make it a palindrome with the fewest operations, prioritizing lexicographically smallest result.

简单
2824

统计和小于目标的下标对数目

This problem asks you to count all index pairs in an array whose sum is strictly less than a given target value efficien…

简单
2825

循环增长使字符串子序列等于另一个字符串

Determine if str2 can be made a subsequence of str1 by incrementing characters cyclically using at most one operation.

中等
2856

删除数对后的最小数组长度

This problem involves minimizing the length of a sorted array by repeatedly removing adjacent pairs of equal elements.

中等
2903

找出满足差值条件的下标 I

Find two indices in an array where their difference in both index and value meets specified thresholds.

简单
2905

找出满足差值条件的下标 II

Locate two indices in an array where both index and value differences meet specified thresholds using precise scanning t…

中等
2911

得到 K 个半回文串的最少修改次数

Minimize the number of letter changes to partition a string into k semi-palindromes using dynamic programming and two po…

困难
2938

区分黑球与白球

Solve the "Separate Black and White Balls" problem by swapping adjacent balls to group all black balls to the right with…

中等
2970

统计移除递增子数组的数目 I

Count the number of incremovable subarrays in an array by removing them to create a strictly increasing sequence.

简单
2972

统计移除递增子数组的数目 II

Count the number of incremovable subarrays where removal of the subarray results in a strictly increasing array.

困难
3006

找出数组中的美丽下标 I

Identify all beautiful indices where substring a appears and a nearby substring b exists within distance k efficiently.

中等
3008

找出数组中的美丽下标 II

Find Beautiful Indices in the Given Array II challenges you to use binary search and string matching techniques.

困难
3132

找出与数组相加的整数 II

Given two arrays nums1 and nums2, determine the integer added to nums1 to make it equal to nums2 after removing two elem…

中等
3186

施咒的最大总伤害

Calculate the maximum total damage by selectively casting spells while avoiding adjacent power conflicts using array sca…

中等
3194

最小元素和最大元素的最小平均值

Solve the Minimum Average of Smallest and Largest Elements problem using two-pointer scanning to track averages effectiv…

简单
3239

最少翻转次数使二进制矩阵回文 I

Find the minimum flips to make a binary grid palindromic by scanning with two pointers and tracking symmetry efficiently…

中等
3240

最少翻转次数使二进制矩阵回文 II

The problem asks to flip cells in a binary grid to make its rows and columns palindromic using the minimum number of fli…

中等
3302

字典序最小的合法序列

Determine the lexicographically smallest valid index sequence by using state transition dynamic programming over word1 a…

中等
3316

从原字符串里进行删除操作的最多次数

Determine the maximum number of characters you can remove from source while keeping pattern as a subsequence using array…

中等
3403

从盒子中找出字典序最大的字符串 I

This problem involves finding the lexicographically largest string from a given word using a two-pointer approach.

中等
3455

最短匹配子字符串

Find the shortest substring in a string that matches a pattern with exactly two wildcards efficiently using binary searc…

困难
3503

子字符串连接后的最长回文串 I

Compute the maximum palindrome length by concatenating substrings from two strings using state transition dynamic progra…

中等
3504

子字符串连接后的最长回文串 II

Compute the longest palindrome by concatenating substrings from two strings using state transition dynamic programming e…

困难
3584

子序列首尾元素的最大乘积

Maximize the product of the first and last elements of any subsequence of size m in an integer array.

中等

关联高频模式

LeetCode 双指针题型题解:182题训练路线