摘要: 8. 209_长度最小的子数组 /* 给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的 连续 子数组,并返回其长度。如果不存在符合条件的子数组,返回 0。 */ class Solution { public int minSubArrayLen(int 阅读全文
posted @ 2020-09-26 19:33 SSunSShine 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 7. 121_买卖股票的最佳时机 /* 输入: [7,1,5,3,6,4] 输出: 5 解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入 阅读全文
posted @ 2020-09-26 19:31 SSunSShine 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 6. 42_接雨水 /* 上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水) */ /* 暴力解, O(n²),O(1) */ class Solution { int trap(int[] height) { 阅读全文
posted @ 2020-09-26 19:30 SSunSShine 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 5. 26_删除排序数组中的重复项 /* 给定 nums = [0,0,1,1,1,2,2,3,3,4], 函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。 你不需要考虑数组中超出新长度后面的元素。 */ class Solution { publ 阅读全文
posted @ 2020-09-26 19:28 SSunSShine 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 4. 16_最接近的三数之和 /* 输入:nums = [-1,2,1,-4], target = 1 输出:2 解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。 */ class Solution { public int threeSumClosest(int[] 阅读全文
posted @ 2020-09-26 19:27 SSunSShine 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 3. 15_三数之和 /* 给定数组 nums = [-1, 0, 1, 2, -1, -4], 判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ? 满足要求的三元组集合为: [ [-1, 0, 1], [-1, -1, 2] ] */ class Solutio 阅读全文
posted @ 2020-09-26 19:26 SSunSShine 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 2. 11_盛最多水的容器 class Solution { public int maxArea(int[] height) { int i = 0, j = height.length-1, res = 0; while(i < j){ int h = Math.min(height[i],he 阅读全文
posted @ 2020-09-26 19:25 SSunSShine 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 1. 3_无重复字符的最长子串 /* 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 */ /** * Hash+双指针滑动窗口 o(n) */ public class Solution { public int lengthOfLon 阅读全文
posted @ 2020-09-26 19:24 SSunSShine 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 6. 206_反转链表 /* 反转一个单链表。 */ class Solution { public ListNode reverseList(ListNode head) { if(head == null || head.next == null) return head; ListNode p 阅读全文
posted @ 2020-09-26 19:23 SSunSShine 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 5. 138_复制带随机指针的链表 /* 给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。 要求返回这个链表的 深拷贝。 我们用一个由 n 个节点组成的链表来表示输入/输出中的链表。每个节点用一个 [val, random_index] 表示: val:一个 阅读全文
posted @ 2020-09-26 19:22 SSunSShine 阅读(93) 评论(0) 推荐(0) 编辑