
双指针
Java”双索引“,一个满指针和一个快指针; 一个正向指针和一个逆向指针。
csdnzhaocsdn
先通俗易懂
再简洁高效
菜但步履不停
所有文章只是学习用没有任何商业盈利若侵权我删
展开
-
680. 验证回文字符串 Ⅱ
给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。示例 1:输入: “aba”输出: True示例 2:输入: “abca”输出: True解释: 你可以删除c字符。注意:字符串只包含从 a-z 的小写字母。字符串的最大长度是50000。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/valid-pali...原创 2020-02-15 11:58:35 · 79 阅读 · 0 评论 -
345. 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母。示例 1:输入: “hello”输出: “holle”示例 2:输入: “leetcode”输出: “leotcede”说明:元音字母不包含字母"y"。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/reverse-vowels-of-a-string著作权归领扣网...原创 2020-02-15 11:33:18 · 86 阅读 · 0 评论 -
633. 平方数之和
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c。示例1:输入: 5输出: True解释: 1 * 1 + 2 * 2 = 5示例2:输入: 3输出: False来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/sum-of-square-numbers著作权归领扣网络所有。商业转载请...原创 2020-02-15 11:31:47 · 100 阅读 · 0 评论 -
259. 较小的三数之和
给定一个长度为 n 的整数数组和一个目标值 target,寻找能够使条件 nums[i] + nums[j] + nums[k] < target 成立的三元组 i, j, k 个数(0 <= i < j < k < n)。示例:输入: nums = [-2,0,1,3], target = 2输出: 2解释: 因为一共有两个三元组满足累加和小于 2:[-...原创 2020-02-11 16:32:29 · 161 阅读 · 0 评论 -
209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead.Example:Input: s = 7, nums...原创 2020-02-11 16:17:25 · 71 阅读 · 0 评论 -
340. Longest Substring with At Most K Distinct Characters
Given a string, find the length of the longest substring T that contains at most k distinct characters.Example 1:Input: s = “eceba”, k = 2Output: 3Explanation: T is “ece” which its length is 3.Ex...原创 2020-02-11 15:47:23 · 138 阅读 · 0 评论 -
159. Longest Substring with At Most Two Distinct Characters
Given a string s , find the length of the longest substring t that contains at most 2 distinct characters.Example 1:Input: “eceba”Output: 3Explanation: t is “ece” which its length is 3.Example 2...原创 2020-02-11 15:23:27 · 179 阅读 · 0 评论 -
80. 删除排序数组中的重复项 II
给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度。不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。示例 1:给定 nums = [1,1,1,2,2,3],函数应返回新长度 length = 5, 并且原数组的前五个元素被修改为 1, 1, 2, 2, 3 。你不需要考虑数组中超出新长度后面的元素...原创 2020-02-10 22:49:43 · 136 阅读 · 0 评论 -
75. 颜色分类
给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。注意:不能使用代码库中的排序函数来解决这道题。示例:输入: [2,0,2,1,1,0]输出: [0,0,1,1,2,2]进阶:一个直观的解决方案是使用计数排序的两趟扫描算法。首先,迭代计...原创 2020-02-10 22:28:07 · 72 阅读 · 0 评论 -
11. 盛最多水的容器
给定 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。示例:输入: [1,8,6,2,5,4,8,3,7]输出: 49来源:力扣(LeetCode)链接:https://leetcode-cn.co...原创 2020-02-10 22:00:10 · 76 阅读 · 0 评论 -
18. 四数之和
给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。注意:答案中不可以包含重复的四元组。示例:给定数组 nums = [1, 0, -1, 0, -2, 2],和 target = 0。满足要求的四元组集合为:[[...原创 2020-02-10 11:17:01 · 84 阅读 · 0 评论 -
16. 最接近的三数之和
给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。例如,给定数组 nums = [-1,2,1,-4], 和 target = 1.与 target 最接近的三个数的和为 2. (-1 + 2 + 1 = 2).来源:力扣(LeetCode)链接:http...原创 2020-02-10 10:07:45 · 79 阅读 · 0 评论 -
15. 三数之和
给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组。注意:答案中不可以包含重复的三元组。示例:给定数组 nums = [-1, 0, 1, 2, -1, -4],满足要求的三元组集合为:[[-1, 0, 1],[-1, -1, 2]]来源:力扣(LeetCode)链接:...原创 2020-02-10 09:35:27 · 83 阅读 · 0 评论 -
148. 排序链表
在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序。示例 1:输入: 4->2->1->3输出: 1->2->3->4示例 2:输入: -1->5->3->4->0输出: -1->0->3->4->5来源:力扣(LeetCode)链接:https://leetcode-cn.c...原创 2020-02-06 11:18:51 · 84 阅读 · 0 评论 -
160. 相交链表
编写一个程序,找到两个单链表相交的起始节点。如下面的两个链表:在节点 c1 开始相交。示例 1:输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3输出:Reference of the node with value = 8输入解释:相交节点的值为 8 (注意,如果两...原创 2020-02-05 22:48:17 · 79 阅读 · 0 评论 -
143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You may not modify the values in the list’s nodes, only nodes itself may be changed.Example 1:Given 1->2->...原创 2020-02-05 16:26:10 · 92 阅读 · 0 评论 -
109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the d...原创 2020-02-05 14:47:12 · 72 阅读 · 0 评论 -
92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5->...原创 2020-02-05 12:32:14 · 128 阅读 · 0 评论 -
86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of th...原创 2020-02-05 11:53:18 · 89 阅读 · 0 评论 -
19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the l...原创 2020-02-04 10:59:28 · 74 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:Input: ...原创 2020-02-02 17:05:38 · 80 阅读 · 0 评论 -
234. Palindrome Linked List
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) time and O(1)...原创 2020-02-02 15:15:30 · 119 阅读 · 0 评论 -
141. 环形链表
给定一个链表,判断链表中是否有环。为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在该链表中没有环。示例 1:输入:head = [3,2,0,-4], pos = 1输出:true解释:链表中有一个环,其尾部连接到第二个节点。示例 2:输入:head = [1,2], pos = 0输出:true解释...原创 2020-02-02 10:40:28 · 84 阅读 · 0 评论 -
243. 最短单词距离
给定一个单词列表和两个单词 word1 和 word2,返回列表中这两个单词之间的最短距离。示例:假设 words = [“practice”, “makes”, “perfect”, “coding”, “makes”]输入: word1 = “coding”, word2 = “practice”输出: 3输入: word1 = “makes”, word2 = “coding”输...原创 2020-01-28 18:21:34 · 283 阅读 · 0 评论 -
167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers s...原创 2020-01-27 22:41:50 · 62 阅读 · 0 评论