Skip to content

feat(公司标签): 1,2,3,4,5,11,15,21,42,53,124,146,206 #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions problems/1.two-sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ https://leetcode-cn.com/problems/two-sum

- 哈希表

## 公司

- 字节、百度、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 字节、百度、腾讯
- 字节跳动
- 百度
- 腾讯


## 思路

最容易想到的就是暴力枚举,我们可以利用两层 for 循环来遍历每个元素,并查找满足条件的目标元素。不过这样时间复杂度为 O(N^2),空间复杂度为 O(1),时间复杂度较高,我们要想办法进行优化。我们可以增加一个 Map 记录已经遍历过的数字及其对应的索引值。这样当遍历一个新数字的时候去 Map 里查询,target 与该数的差值是否已经在前面的数字中出现过。如果出现过,那么已经得出答案,就不必再往下执行了。
Expand Down
4 changes: 4 additions & 0 deletions problems/11.container-with-most-water.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ https://leetcode-cn.com/problems/container-with-most-water/description/

- 双指针

## 公司

- 字节
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 字节
- 字节跳动


## 思路

题目中说`找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。` ,因此符合直觉的解法就是固定两个端点,计算可以承载的水量, 然后不断更新最大值,最后返回最大值即可。这种算法,需要两层循环,时间复杂度是 $O(n^2)$。
Expand Down
4 changes: 4 additions & 0 deletions problems/124.binary-tree-maximum-path-sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Output: 42

- 递归

## 公司

- 字节
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 字节
- 字节跳动


## 思路

这道题目的path让我误解了,然后浪费了很多时间来解这道题
Expand Down
4 changes: 4 additions & 0 deletions problems/146.lru-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ cache.get(4); // returns 4

- 队列

## 公司

- 百度、字节
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 百度、字节
- 百度
- 字节跳动


## 思路

`本题已被收录到我的新书中,敬请期待~`
Expand Down
4 changes: 4 additions & 0 deletions problems/15.3-sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ A solution set is:
- 双指针
- 分治

## 公司

- 阿里、字节
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、字节
- 阿里巴巴
- 字节跳动


## 思路

我们采用`分治`的思想. 想要找出三个数相加等于 0,我们可以数组依次遍历,
Expand Down
4 changes: 4 additions & 0 deletions problems/2.add-two-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Explanation: 342 + 465 = 807.

- 链表

## 公司

- 阿里、百度、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、百度、腾讯
- 阿里巴巴
- 百度
- 腾讯


## 思路

设立一个表示进位的变量 carried,建立一个新链表,
Expand Down
4 changes: 4 additions & 0 deletions problems/206.reverse-linked-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ A linked list can be reversed either iteratively or recursively. Could you imple

- 链表

## 公司

- 阿里、百度、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、百度、腾讯
- 阿里巴巴
- 百度
- 腾讯


## 思路

这个就是常规操作了,使用一个变量记录前驱 pre,一个变量记录后继 next.
Expand Down
4 changes: 4 additions & 0 deletions problems/21.merge-two-sorted-lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ https://leetcode-cn.com/problems/merge-two-sorted-lists
- 递归
- 链表

## 公司

- 阿里、字节、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、字节、腾讯
- 阿里
- 字节跳动
- 腾讯


## 思路

使用递归来解题,将两个链表头部较小的一个与剩下的元素合并,并返回排好序的链表头,当两条链表中的一条为空时终止递归。
Expand Down
4 changes: 4 additions & 0 deletions problems/3.longest-substring-without-repeating-characters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

## 公司

- 阿里、字节、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、字节、腾讯
- 阿里巴巴
- 字节跳动
- 腾讯


## 思路

用一个 hashmap 来建立字符和其出现位置之间的映射。同时维护一个滑动窗口,窗口内的都是没有重复的字符,去尽可能的扩大窗口的大小,窗口不停的向右滑动。
Expand Down
4 changes: 4 additions & 0 deletions problems/4.median-of-two-sorted-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ nums2 = [3, 4]
- 分治法
- 二分查找

## 公司

- 阿里、百度、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、百度、腾讯
- 阿里巴巴
- 百度
- 腾讯


## 思路

首先了解一下 Median 的概念,一个数组中 median 就是把数组分成左右等分的中位数。
Expand Down
4 changes: 4 additions & 0 deletions problems/42.trapping-rain-water.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Output: 6
- 双指针
- 单调栈

## 公司

- 字节
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 字节
- 字节跳动


## 双数组

### 思路
Expand Down
4 changes: 4 additions & 0 deletions problems/5.longest-palindromic-substring.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ https://leetcode-cn.com/problems/longest-palindromic-substring/

- 回文

## 公司

- 阿里、百度、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、百度、腾讯
- 阿里巴巴
- 百度
- 腾讯


## 思路

这是一道最长回文的题目,要我们求出给定字符串的最大回文子串。
Expand Down
4 changes: 4 additions & 0 deletions problems/53.maximum-sum-subarray-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```

## 公司

- 阿里、百度、字节、腾讯
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 阿里、百度、字节、腾讯
- 阿里巴巴
- 百度
- 字节跳动
- 腾讯


## 思路

这道题求解连续最大子序列和,以下从时间复杂度角度分析不同的解题思路。
Expand Down