From 5a63c1b88dbfa5ea074c008451dd7f737ceca233 Mon Sep 17 00:00:00 2001 From: ygy Date: Fri, 17 Jul 2020 23:46:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=85=AC=E5=8F=B8=E6=A0=87=E7=AD=BE):=201?= =?UTF-8?q?=EF=BC=8C2=EF=BC=8C3=EF=BC=8C4=EF=BC=8C5=EF=BC=8C11=EF=BC=8C15?= =?UTF-8?q?=EF=BC=8C21=EF=BC=8C42=EF=BC=8C53=EF=BC=8C124=EF=BC=8C146?= =?UTF-8?q?=EF=BC=8C206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1.two-sum.md | 4 ++++ problems/11.container-with-most-water.md | 4 ++++ problems/124.binary-tree-maximum-path-sum.md | 4 ++++ problems/146.lru-cache.md | 4 ++++ problems/15.3-sum.md | 4 ++++ problems/2.add-two-numbers.md | 4 ++++ problems/206.reverse-linked-list.md | 4 ++++ problems/21.merge-two-sorted-lists.md | 4 ++++ problems/3.longest-substring-without-repeating-characters.md | 4 ++++ problems/4.median-of-two-sorted-array.md | 4 ++++ problems/42.trapping-rain-water.md | 4 ++++ problems/5.longest-palindromic-substring.md | 4 ++++ problems/53.maximum-sum-subarray-cn.md | 4 ++++ 13 files changed, 52 insertions(+) diff --git a/problems/1.two-sum.md b/problems/1.two-sum.md index c5dc33ea2..0ce7a4847 100644 --- a/problems/1.two-sum.md +++ b/problems/1.two-sum.md @@ -21,6 +21,10 @@ https://leetcode-cn.com/problems/two-sum - 哈希表 +## 公司 + +- 字节、百度、腾讯 + ## 思路 最容易想到的就是暴力枚举,我们可以利用两层 for 循环来遍历每个元素,并查找满足条件的目标元素。不过这样时间复杂度为 O(N^2),空间复杂度为 O(1),时间复杂度较高,我们要想办法进行优化。我们可以增加一个 Map 记录已经遍历过的数字及其对应的索引值。这样当遍历一个新数字的时候去 Map 里查询,target 与该数的差值是否已经在前面的数字中出现过。如果出现过,那么已经得出答案,就不必再往下执行了。 diff --git a/problems/11.container-with-most-water.md b/problems/11.container-with-most-water.md index dfb6ab83d..d53a286d6 100644 --- a/problems/11.container-with-most-water.md +++ b/problems/11.container-with-most-water.md @@ -30,6 +30,10 @@ https://leetcode-cn.com/problems/container-with-most-water/description/ - 双指针 +## 公司 + +- 字节 + ## 思路 题目中说`找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。` ,因此符合直觉的解法就是固定两个端点,计算可以承载的水量, 然后不断更新最大值,最后返回最大值即可。这种算法,需要两层循环,时间复杂度是 $O(n^2)$。 diff --git a/problems/124.binary-tree-maximum-path-sum.md b/problems/124.binary-tree-maximum-path-sum.md index a5b31b040..4c42192c9 100644 --- a/problems/124.binary-tree-maximum-path-sum.md +++ b/problems/124.binary-tree-maximum-path-sum.md @@ -35,6 +35,10 @@ Output: 42 - 递归 +## 公司 + +- 字节 + ## 思路 这道题目的path让我误解了,然后浪费了很多时间来解这道题 diff --git a/problems/146.lru-cache.md b/problems/146.lru-cache.md index 9060024b0..7f8d56816 100644 --- a/problems/146.lru-cache.md +++ b/problems/146.lru-cache.md @@ -32,6 +32,10 @@ cache.get(4); // returns 4 - 队列 +## 公司 + +- 百度、字节 + ## 思路 `本题已被收录到我的新书中,敬请期待~` diff --git a/problems/15.3-sum.md b/problems/15.3-sum.md index 16560bd8a..aef591950 100644 --- a/problems/15.3-sum.md +++ b/problems/15.3-sum.md @@ -29,6 +29,10 @@ A solution set is: - 双指针 - 分治 +## 公司 + +- 阿里、字节 + ## 思路 我们采用`分治`的思想. 想要找出三个数相加等于 0,我们可以数组依次遍历, diff --git a/problems/2.add-two-numbers.md b/problems/2.add-two-numbers.md index 1b395058e..1763ac68c 100644 --- a/problems/2.add-two-numbers.md +++ b/problems/2.add-two-numbers.md @@ -21,6 +21,10 @@ Explanation: 342 + 465 = 807. - 链表 +## 公司 + +- 阿里、百度、腾讯 + ## 思路 设立一个表示进位的变量 carried,建立一个新链表, diff --git a/problems/206.reverse-linked-list.md b/problems/206.reverse-linked-list.md index bc8b44723..d86affa6d 100644 --- a/problems/206.reverse-linked-list.md +++ b/problems/206.reverse-linked-list.md @@ -18,6 +18,10 @@ A linked list can be reversed either iteratively or recursively. Could you imple - 链表 +## 公司 + +- 阿里、百度、腾讯 + ## 思路 这个就是常规操作了,使用一个变量记录前驱 pre,一个变量记录后继 next. diff --git a/problems/21.merge-two-sorted-lists.md b/problems/21.merge-two-sorted-lists.md index 20435388d..79eecf103 100644 --- a/problems/21.merge-two-sorted-lists.md +++ b/problems/21.merge-two-sorted-lists.md @@ -19,6 +19,10 @@ https://leetcode-cn.com/problems/merge-two-sorted-lists - 递归 - 链表 +## 公司 + +- 阿里、字节、腾讯 + ## 思路 使用递归来解题,将两个链表头部较小的一个与剩下的元素合并,并返回排好序的链表头,当两条链表中的一条为空时终止递归。 diff --git a/problems/3.longest-substring-without-repeating-characters.md b/problems/3.longest-substring-without-repeating-characters.md index f1ee1e5a8..198395319 100644 --- a/problems/3.longest-substring-without-repeating-characters.md +++ b/problems/3.longest-substring-without-repeating-characters.md @@ -21,6 +21,10 @@ Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer - 哈希表 - [滑动窗口](https://github.com/azl397985856/leetcode/blob/master/thinkings/slide-window.md) +## 公司 + +- 阿里、字节、腾讯 + ## 思路 用一个 hashmap 来建立字符和其出现位置之间的映射。同时维护一个滑动窗口,窗口内的都是没有重复的字符,去尽可能的扩大窗口的大小,窗口不停的向右滑动。 diff --git a/problems/4.median-of-two-sorted-array.md b/problems/4.median-of-two-sorted-array.md index 781fb4acc..067ff8285 100644 --- a/problems/4.median-of-two-sorted-array.md +++ b/problems/4.median-of-two-sorted-array.md @@ -34,6 +34,10 @@ nums2 = [3, 4] - 分治法 - 二分查找 +## 公司 + +- 阿里、百度、腾讯 + ## 思路 首先了解一下 Median 的概念,一个数组中 median 就是把数组分成左右等分的中位数。 diff --git a/problems/42.trapping-rain-water.md b/problems/42.trapping-rain-water.md index 5b3fe24ac..8938e6b27 100755 --- a/problems/42.trapping-rain-water.md +++ b/problems/42.trapping-rain-water.md @@ -29,6 +29,10 @@ Output: 6 - 双指针 - 单调栈 +## 公司 + +- 字节 + ## 双数组 ### 思路 diff --git a/problems/5.longest-palindromic-substring.md b/problems/5.longest-palindromic-substring.md index 422d992af..382a802b7 100644 --- a/problems/5.longest-palindromic-substring.md +++ b/problems/5.longest-palindromic-substring.md @@ -20,6 +20,10 @@ https://leetcode-cn.com/problems/longest-palindromic-substring/ - 回文 +## 公司 + +- 阿里、百度、腾讯 + ## 思路 这是一道最长回文的题目,要我们求出给定字符串的最大回文子串。 diff --git a/problems/53.maximum-sum-subarray-cn.md b/problems/53.maximum-sum-subarray-cn.md index 7f09c6cd7..a81f80423 100644 --- a/problems/53.maximum-sum-subarray-cn.md +++ b/problems/53.maximum-sum-subarray-cn.md @@ -15,6 +15,10 @@ Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle. ``` +## 公司 + +- 阿里、百度、字节、腾讯 + ## 思路 这道题求解连续最大子序列和,以下从时间复杂度角度分析不同的解题思路。