
双指针
str_818
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【Leetcode】167. 两数之和 II - 输入有序数组(Two Sum II - Input array is sorted)
Leetcode - 167 Two Sum II - Input array is sorted (Easy)题目描述:给定一个升序数组,找到两个数使得两数之和为 target。Input: numbers = [2,7,11,15], target = 9Output: [1,2]Explanation: The sum of 2 and 7 is 9. Therefore index...原创 2019-05-30 10:33:14 · 371 阅读 · 0 评论 -
【Leetcode】977. 数组平方的排序(Squares of a Sorted Array)
Leetcode - 977 Squares of a Sorted Array (Easy)题目描述:给定一个升序数组,对每一个元素进行平方运算,运算后的数组依然升序。Input: [-4,-1,0,3,10]Output: [0,1,9,16,100]解题思路:双指针。从数组的两端开始向中间遍历,比较两个元素找出最大的元素。public int[] sortedSquares(in...原创 2019-05-27 20:34:31 · 317 阅读 · 0 评论 -
【Leetcode】830. 较大分组的位置(Positions of Large Groups)
Leetcode - 830 Positions of Large Groups (Easy)题目描述:给定一个字符串由连续相同的字母组成,找出连续字母数量超过 3 的起始位置。Input: "abbxxxxzzy"Output: [[3,6]]Explanation: "xxxx" is the single large group with starting 3 and ending...原创 2019-05-31 11:13:44 · 166 阅读 · 0 评论 -
【Leetcode】27. 移除元素(Remove Element)
Leetcode - 27 Remove Element (Easy)题目描述:在不使用额外空间的情况下,删除数组中的 val,返回删除后的数组长度。Given nums = [3,2,2,3], val = 3,Your function should return length = 2, with the first two elements of nums being 2.It ...原创 2019-06-01 10:54:33 · 200 阅读 · 0 评论 -
【Leetcode】3. 无重复字符的最长子串(Longest Substring Without Repeating Characters)
Leetcode - 3 Longest Substring Without Repeating Characters (Medium)Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. 解题思路:使用 HashMap 记录出现字符的位置,利用双指针滑动窗口记录子串的长度。...原创 2019-06-02 11:28:31 · 172 阅读 · 0 评论 -
【Leetcode】11. 盛最多水的容器(Container With Most Water)
Leetcode - 11 Container With Most Water (Medium)题目描述:找出两条线,使得构成的容器能够容纳最多的水。 public int maxArea(int[] height) { int max = 0, i = 0, j = height.length - 1; while (i < j) { max = ...原创 2019-06-03 10:07:08 · 155 阅读 · 0 评论 -
【Leetcode】42. 接雨水(Trapping Rain Water)
Leetcode - 42 Trapping Rain Water (Hard)题目描述:给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 Input: [0,1,0,2,1,0,1,3,2,1,2,1]Output: 6解题思路:双指针public int trap(int[] height) { int left = ...原创 2019-06-09 09:19:56 · 328 阅读 · 0 评论 -
【Leetcode】19. 删除链表的倒数第 n 个节点(Remove Nth Node From End of List)
Leetcode - 19 Remove Nth Node From End of List (Medium)Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becomes 1->2->3->...原创 2019-06-04 09:02:57 · 197 阅读 · 0 评论 -
【Leetcode】26. 删除有序数组中的重复项(Remove Duplicates from Sorted Array)
Leetcode - 26 Remove Duplicates from Sorted Array (Easy)Given nums = [0,0,1,1,1,2,2,3,3,4],Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3,...原创 2019-06-05 08:32:15 · 658 阅读 · 0 评论