![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
稻云麦花
跑路回家
展开
-
LeetCode Two Sum&Two Sum II - Input array is sorted&3Sum&4Sum 一锅煮题解
文章目录Two SumTwo Sum II3Sum4SumTwo Sum题意给定一个数组,和指定一个目标和。从数组中选择两个数满足和为目标和。保证有且只有一个解。每个元素只可以用一次。思路Hash表快速查询值是否在数组中存在。枚举一个数,查询另一个数是否存在。注意:虽然一个元素只可以使用一次,但是数组中可以出现重复的元素。复杂度T(N)=O(N),M(N)=O(N)T(N)=O...原创 2019-02-18 01:11:03 · 145 阅读 · 0 评论 -
LeetCode 3sum-closest 题解
思路排序枚举一个数a双指针移动法确定b和c求和,更新最接近的值复杂度T(n)=O(n2)  M(n)=O(1)T(n)=O(n^2) \; M(n)=O(1)T(n)=O(n2)M(n)=O(1)class Solution { public int threeSumClosest(int[] nums,int target) { ...原创 2019-02-18 01:42:36 · 120 阅读 · 0 评论 -
LeetCode subarray-sum-equals-k题解 前缀和+Hash表+枚举——线性做法
文章目录题意思路连续子数组的和sum[i,j]源码结果记录题意给定一个数组,求连续的子数组的和为k的子数组个数。思路连续子数组的和sum[i,j]sum[i,j]=∑k=ijAk(i&lt;j)sum[i,j]=\sum_{k=i}^jA_k(i&lt;j)sum[i,j]=∑k=ijAk(i<j)即数组第i个数到第j个数的子数组的和。sum[i,j]=su...原创 2019-02-18 13:52:01 · 302 阅读 · 0 评论 -
LeetCode Continuous Subarray Sum 题解 同余前缀和 Hash表
文章目录题意思路特殊情况k=0Source Code 1Source Code 2题意给定一个数组和一个整数k,返回是否存在一个长度至少为2的连续子数组的和为k的倍数。思路和上一篇博客的思路基本一致。LeetCode subarray-sum-equals-k题解所不同的是,子数组至少长度为2。因此需要一个缓冲区,延缓往Hash表中加数的操作。另外,因为是和变成是k的倍数。利用同余的...原创 2019-02-18 15:09:21 · 154 阅读 · 0 评论 -
LeetCode Subarray Product Less Than K 题解 双指针+单调性
题意给定一个正整数数组和K,数有多少个连续子数组满足:数组中所有的元素的积小于K.思路依旧是双指针的思路我们首先固定右指针r.现在子数组的最右边的元素是nums[r].我们让这个子数组尽可能的长,尽可能的往左边拓展,假设最左边的元素的前一个元素是l.即子数组(l,r].显然对于以nums[r]结尾的满足题意的数组个数为r−lr-lr−l对于(l1,r1],&Thick...原创 2019-02-18 16:05:37 · 130 阅读 · 0 评论 -
LeetCodeTwo Sum IV 树的遍历+Hash大法好
题意给定一颗二叉搜索树,取是否存在两个节点的值之和为给定值K.思路同Two Sum.使用Hash表解决。只是要写个树的遍历而已,选取DFS.源码class Solution { public boolean findTarget(TreeNode root, int k) { return work(root,k,new HashSet&amp;lt;Integer&amp;gt...原创 2019-02-18 16:32:40 · 172 阅读 · 0 评论 -
LeetCode 第二题 Add Two Numbers 大整数加法 高精度加法 链表
题意You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and retur...原创 2019-02-18 17:51:16 · 257 阅读 · 0 评论 -
LeetCode longest substring without repeating characters 题解 Hash表
题目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:Inpu...原创 2019-02-18 21:12:35 · 84 阅读 · 0 评论 -
LeetCode 第四题 Median of Two Sorted Arrays 二人 渣渣选手乱七八糟分析发现基本回到思路1
题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 and ...原创 2019-02-19 16:51:36 · 120 阅读 · 0 评论