双指针
文章平均质量分 88
memcpy0
希望探索文理结合的自由之路。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 2095. 删除链表的中间节点【链表,快慢指针】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2026-06-16 01:51:49 · 245 阅读 · 0 评论 -
LeetCode 2540. 最小公共值【双序列双指针】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2026-05-31 17:17:31 · 220 阅读 · 0 评论 -
LeetCode 3643. 垂直翻转子矩阵【双指针】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2026-03-21 04:07:50 · 399 阅读 · 0 评论 -
LeetCode 3132. 找出与数组相加的整数 II【排序,同向双指针;技巧】中等【Py3,Java,C++,C,GO,JS,Rust】
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2024-08-10 01:55:04 · 986 阅读 · 0 评论 -
LeetCode 2105. 给植物浇水 II【相向双指针模拟】1507
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2024-05-10 02:04:31 · 719 阅读 · 0 评论 -
LeetCode 2905. 找出满足差值条件的下标 II【双指针+维护最小最大值】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-10-16 10:51:50 · 273 阅读 · 0 评论 -
LeetCode 2903. 找出满足差值条件的下标 I【双指针+维护最大最小】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-10-16 10:14:47 · 242 阅读 · 0 评论 -
LeetCode 2562. 找出数组的串联值【数组,相向双指针】1259
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-10-13 15:43:11 · 278 阅读 · 0 评论 -
2511. Maximum Enemy Forts That Can Be Captured【数组,双指针】1450
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。原创 2023-09-05 09:25:49 · 168 阅读 · 0 评论 -
LeetCode 2337. Move Pieces to Obtain a String【字符串,双指针】1693
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-08-22 00:06:13 · 357 阅读 · 0 评论 -
LeetCode 88. Merge Sorted Array【数组,双指针】简单
为两个数组分别设置一个指针。原创 2023-08-20 15:25:05 · 784 阅读 · 0 评论 -
LeetCode 436. Find Right Interval【排序,二分;双指针,莫队】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-07-29 13:31:43 · 633 阅读 · 0 评论 -
LeetCode 2465. Number of Distinct Averages【哈希表,双指针,排序】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-06-05 13:35:54 · 849 阅读 · 0 评论 -
LeetCode 2460. Apply Operations to an Array【数组,模拟,双指针】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2023-06-05 13:34:37 · 864 阅读 · 0 评论 -
LeetCode 2367. Number of Arithmetic Triplets【哈希表,三指针】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的。原创 2023-04-01 02:06:15 · 695 阅读 · 0 评论 -
LeetCode 1616. Split Two Strings to Make Palindrome【字符串,双指针】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。原创 2023-03-18 20:57:38 · 881 阅读 · 0 评论 -
LeetCode 1237. Find Positive Integer Solution for a Given Equation【双指针,二分,交互】
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还建立了相关的。原创 2023-03-01 04:22:27 · 233 阅读 · 0 评论 -
LeetCode 剑指 Offer 22. 链表中倒数第k个节点【链表/双指针】简单
输入一个链表,输出该链表中倒数第 k 个节点。为了符合大多数人的习惯,本题从 1 开始计数,即链表的尾节点是倒数第 1 个节点。例如,一个链表有 6 个节点,从头节点开始,它们的值依次是 1、2、3、4、5、6 。这个链表的倒数第 3 个节点是值为 4 的节点。示例:给定一个链表: 1->2->3->4->5, 和 k = 2.返回链表 4->5.解法 快慢指针class Solution {public: ListNode* getKthFromEn原创 2020-11-14 10:16:21 · 410 阅读 · 0 评论 -
LeetCode 443. String Compression【字符串/双指针】中等
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,这个截止期限可能是永远。在这一系列刷题文章中,不仅讲解多种解体思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时还会总结相应的算法模板。为了方便在PC上运行调试、分享代码文件,我还将建立相关的仓库:https://github.com/memcpy0/LeetCode-Conquest。在这一.原创 2021-08-22 20:25:03 · 543 阅读 · 0 评论 -
LeetCode 413. Arithmetic Slices【数组/双指针/动态规划】中等
An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences.Given an integer arra原创 2021-08-13 22:49:15 · 450 阅读 · 0 评论 -
LeetCode C++ 1861. Rotating the Box【Queue/Two Pointers】中等
You are given an m x n matrix of characters box representing a side-view of a box. Each cell of the box is one of the following: A stone '#' A stationary obstacle '*' Empty '.'The box is rotated 90 degrees clockwise, causing some of the stones to fal原创 2021-05-18 02:37:18 · 544 阅读 · 1 评论 -
LeetCode 1855. 下标对中的最大距离【数组,二分;同向双指针】中等
You are given two non-increasing 0-indexed integer arrays nums1 and nums2.A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the原创 2021-05-14 01:17:21 · 435 阅读 · 1 评论 -
LeetCode C++ 面试题 17.11. Find Closest LCCI【Two Pointers/Hash Table】中等
You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many times for the same file (but different pairs of words), can you opti原创 2021-01-05 23:57:30 · 477 阅读 · 0 评论 -
LeetCode C++ 27. Remove Element【Array/Two Pointers】简单
Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.The order of elements原创 2020-12-04 17:33:11 · 584 阅读 · 0 评论 -
LeetCode C++ 26. Remove Duplicates from Sorted Array【Array/Two Pointers】简单
Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.Cla原创 2020-12-04 16:25:40 · 457 阅读 · 0 评论 -
LeetCode 287. Find the Duplicate Number【Array/Two Pointers】中等
Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.There is only one duplicate number in nums, return this duplicate number.Follow-ups:How can we prove that at least one duplicate number must e原创 2020-11-25 23:39:04 · 370 阅读 · 0 评论 -
LeetCode 142. Linked List Cycle II【链表,哈希表;双指针】
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally,原创 2020-11-25 22:18:41 · 458 阅读 · 0 评论 -
LeetCode C++ 160. Intersection of Two Linked Lists【Linked List/Two Pointers】简单
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1.Example 1:Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skip原创 2020-11-17 01:10:45 · 356 阅读 · 0 评论 -
LeetCode 876. 链表的中间结点【快慢指针】简单
本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。。原创 2020-11-14 13:35:42 · 394 阅读 · 0 评论 -
LeetCode C++ 492. Construct the Rectangle【Math/Two Pointers】简单
A web developer needs to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:The area of the rectangula原创 2020-11-05 01:42:03 · 414 阅读 · 0 评论 -
LeetCode C++ 941. Valid Mountain Array【Array/Two Pointers】简单
Given an array A of integers, return true if and only if it is a valid mountain array.Recall that A is a mountain array if and only if:A.length >= 3There exists some i with 0 < i < A.length - 1 such that:A[0] < A[1] < ... A[i-1] < A原创 2020-10-23 18:38:29 · 344 阅读 · 0 评论 -
LeetCode C++ 845. Longest Mountain in Array【Two Pointers】中等
Let’s call any (contiguous) subarray B (of A) a mountain if the following properties hold:B.length >= 3There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1](Note th原创 2020-10-25 10:07:39 · 355 阅读 · 0 评论 -
LeetCode 234. 回文链表【链表,递归;快慢指针,迭代】简单
Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up: Could you do it in O(n)O(n)O(n) time and O(1)O(1)O(1) space?题意:判断一个单链表是否是回文链表。解法1 复制链表值原创 2020-10-23 15:48:32 · 557 阅读 · 0 评论 -
LeetCode C++ 61. Rotate List【Linked List/Two Pointers】中等
Given a linked list, rotate the list to the right by k places, where k is non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExplanation:rotate 1 steps to the right: 5->1->2->3->原创 2020-10-22 20:29:27 · 351 阅读 · 0 评论 -
LeetCode C++ 925. Long Pressed Name【String/Two Pointers】简单
Your friend is typing his name into a keyboard. Sometimes, when typing a character c , the key might get long pressed, and the character will be typed 1 or more times.You examine the typed characters of the keyboard. Return True if it is possible that i原创 2020-10-21 10:57:01 · 396 阅读 · 0 评论 -
LeetCode 844. 比较含退格的字符串【字符串,快慢指针或栈】简单
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.Note that after backspacing an empty text, the text will continue empty.Example 1:Input: S = "ab#c", T = "ad#c"Output: trueE原创 2020-10-20 17:36:38 · 612 阅读 · 1 评论 -
LeetCode C++ 19. Remove Nth Node From End of List【链表/双指针】中等
Given the head of a linked list, remove the nth node from the end of the list and return its head.Follow up: Could you do this in one pass?Example 1:Input: head = [1,2,3,4,5], n = 2Output: [1,2,3,5]Example 2:Input: head = [1], n = 1Output: []Exa原创 2020-10-18 10:14:08 · 372 阅读 · 0 评论 -
LeetCode C++ 653. Two Sum IV - Input is a BST【Binary Search Tree/Two Pointers/Recursion】简单
Given the root of a Binary Search Tree and a target number k, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input: root = [5,3,6,2,4,null,7], k = 9Output: trueExample 2:Input: root = [原创 2020-10-16 21:06:16 · 540 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle【链表,双指针】简单
Given head , the head of a linked list, determine if the linked list has a cycle in it.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to den原创 2020-10-09 11:28:46 · 357 阅读 · 0 评论 -
LeetCode 345. Reverse Vowels of a String【双指针】简单
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Input: "hello"Output: "holle"Example 2:Input: "leetcode"Output: "leotcede"Note: The vowels does not include the letter "y" .题意:编写一个函数,以字符串作为输入,反转该字符串中原创 2020-10-08 15:12:51 · 568 阅读 · 0 评论
分享