Skip to content

Commit 9bbe26f

Browse files
Update
1 parent 4a0d040 commit 9bbe26f

File tree

5 files changed

+156
-11
lines changed

5 files changed

+156
-11
lines changed

README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
# leetcode
1+
# Leetcode精选:
22

3-
LeetCode 最强题解(持续更新中):
3+
* [leetcode面试高频题目题解](https://github.com/youngyangyang04/leetcode-master)
4+
* [究竟什么是时间复杂度,怎么求时间复杂度,看这一篇就够了](https://mp.weixin.qq.com/s/ma615my-adxMNKmzcdYVlg)
5+
* [一文带你彻底理解程序为什么会超时](https://mp.weixin.qq.com/s/ZLHsvkxppD8QJMBj3njOiw)
6+
* [一场面试,带你彻底掌握递归算法的时间复杂度](https://mp.weixin.qq.com/s/GOYVzUVrfLUjOrDg21YOAw)
7+
* [算法分析中的空间复杂度,你真的会了么?](https://mp.weixin.qq.com/s/uU6cn0SYRUbIf5tU2QkcOQ)
8+
* [二分法其实很简单,为什么老是写不对!!](https://mp.weixin.qq.com/s/mZ87E2vdvqhbv55uYpdrAQ)
9+
* [程序员算法面试中,必须掌握的数组理论知识](https://mp.weixin.qq.com/s/hgSxlgs12IQPUvG0BQukBg)
10+
* [这五道数组相关的面试题,你一定要会!](https://mp.weixin.qq.com/s/tMgABUtR1Ydv330NogS3Jg)
11+
* [关于哈希表,你该了解这些!](https://mp.weixin.qq.com/s/UnuQIRZSn_i2G4VhTWK5CQ)
12+
* 精选链表相关的面试题
13+
* 精选哈希表相关的面试题
14+
* 精选字符串相关的面试题
15+
* 精选栈与队列相关的面试题
16+
* 精选二叉树相关的面试题
17+
* 精选递归与回溯面试题
18+
19+
20+
# LeetCode 最强题解:
421

522
|题目 | 类型 | 难度 | 解题方法 |
623
|---|---| ---| --- |
@@ -28,8 +45,10 @@ LeetCode 最强题解(持续更新中):
2845
|[0225.用队列实现栈](https://github.com/youngyangyang04/leetcode/blob/master/problems/0225.用队列实现栈.md) | 队列 |简单| **队列** |
2946
|[0232.用栈实现队列](https://github.com/youngyangyang04/leetcode/blob/master/problems/0232.用栈实现队列.md) ||简单| **** |
3047
|[0237.删除链表中的节点](https://github.com/youngyangyang04/leetcode/blob/master/problems/0237.删除链表中的节点.md) |链表 |简单| **原链表移除** **添加虚拟节点** 递归|
48+
|[0239.滑动窗口最大值](https://github.com/youngyangyang04/leetcode/blob/master/problems/0239.滑动窗口最大值.md) |滑动窗口/队列 |困难| **单调队列**|
3149
|[0242.有效的字母异位词](https://github.com/youngyangyang04/leetcode/blob/master/problems/0242.有效的字母异位词.md) |哈希表 |简单| **哈希**|
3250
|[0344.反转字符串](https://github.com/youngyangyang04/leetcode/blob/master/problems/0344.反转字符串.md) |字符串 |简单| **双指针**|
51+
|[0347.前K个高频元素](https://github.com/youngyangyang04/leetcode/blob/master/problems/0347.前K个高频元素.md) |哈希/堆/优先级队列 |中等| **哈希/优先级队列**|
3352
|[0349.两个数组的交集](https://github.com/youngyangyang04/leetcode/blob/master/problems/0349.两个数组的交集.md) |哈希表 |简单|**哈希**|
3453
|[0350.两个数组的交集II](https://github.com/youngyangyang04/leetcode/blob/master/problems/0350.两个数组的交集II.md) |哈希表 |简单|**哈希**|
3554
|[0383.赎金信](https://github.com/youngyangyang04/leetcode/blob/master/problems/0383.赎金信.md) |数组 |简单|**暴力** **字典计数** **哈希**|
@@ -41,15 +60,18 @@ LeetCode 最强题解(持续更新中):
4160
|[1047.删除字符串中的所有相邻重复项](https://github.com/youngyangyang04/leetcode/blob/master/problems/1047.删除字符串中的所有相邻重复项.md) ||简单|****|
4261
|[剑指Offer05.替换空格](https://github.com/youngyangyang04/leetcode/blob/master/problems/剑指Offer05.替换空格.md) |字符串 |简单|**双指针**|
4362

44-
Leetcode精选:
45-
46-
* [精选数组相关的面试题](https://mp.weixin.qq.com/s?__biz=Mzg5MTExMTk2OA==&mid=2247484000&idx=1&sn=48e87c8ca22390ac5e78bcbb45e2052c&chksm=cfd31d2ff8a4943916305f519d963d1c0979f112abd6f613af7bdb7fa6ec3f86e8c93c2e0caa&token=411961669&lang=zh_CN#rd)
47-
48-
* [精选链表相关的面试题]()
49-
5063
持续更新中....
5164

5265
> 笔者介绍:
5366
> ACM亚洲区域赛铜牌获得者,哈工大计算机硕士毕业后,先后在腾讯和百度工作多年,对算法和后端技术有一定的见解,利用工作之余重新刷leetcode
54-
> 欢迎关注微信公众号:「代码随想录」,这里将持续分享自己对互联网以及技术的想法与思考
67+
> 更多精彩文章持续更新,微信搜索:「代码随想录」第一时间围观,关注后回复: 「简历模板」「java」「C++」「python」「算法与数据结构」 等关键字就可以获得我多年整理出来的学习资料。
68+
69+
# 联系我
70+
71+
<a name="微信"></a>
72+
<img src="https://img-blog.csdnimg.cn/20200712232919673.jpeg" data-img="1" width="175" height="175">
73+
74+
# 我的公众号
75+
<a name="公众号"></a>
76+
<img src="https://img-blog.csdnimg.cn/20200323202104335.jpg" data-img="1" width="200" height="200">
5577

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## 题目地址
2+
https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/
3+
4+
## 思路
5+
6+
这道题目相当于是二叉树中的后序遍历,也引申出栈与递归之间在某种程度上是可以转换的!
7+
8+
## C++代码
9+
10+
```
11+
class Solution {
12+
public:
13+
int evalRPN(vector<string>& tokens) {
14+
stack<int> st;
15+
for (int i = 0; i < tokens.size(); i++) {
16+
if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/") {
17+
int num1 = st.top();
18+
st.pop();
19+
int num2 = st.top();
20+
st.pop();
21+
if (tokens[i] == "+") st.push(num2 + num1);
22+
if (tokens[i] == "-") st.push(num2 - num1);
23+
if (tokens[i] == "*") st.push(num2 * num1);
24+
if (tokens[i] == "/") st.push(num2 / num1);
25+
} else {
26+
st.push(stoi(tokens[i]));
27+
}
28+
}
29+
return st.top();
30+
}
31+
};
32+
```
33+
> 笔者在先后在腾讯和百度从事技术研发多年,利用工作之余重刷leetcode,本文 [GitHub](https://github.com/youngyangyang04/leetcode-master )https://github.com/youngyangyang04/leetcode-master 已经收录,欢迎star,fork,共同学习,一起进步。
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## 题目地址
2+
https://leetcode-cn.com/problems/sliding-window-maximum/
3+
4+
## 思路
5+
6+
7+
## C++代码
8+
9+
```
10+
class Solution {
11+
public:
12+
class MyQueue {
13+
public:
14+
deque<int> que;
15+
void pop(int value) {
16+
if (!que.empty() && value == que.front()) {
17+
que.pop_front();
18+
}
19+
}
20+
void push(int value) {
21+
while (!que.empty() && value > que.back()) {
22+
que.pop_back();
23+
}
24+
que.push_back(value);
25+
26+
}
27+
int front() {
28+
return que.front();
29+
}
30+
};
31+
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
32+
MyQueue que;
33+
vector<int> result;
34+
for (int i = 0; i < k; i++) {
35+
que.push(nums[i]);
36+
}
37+
result.push_back(que.front());
38+
for (int i = k; i < nums.size(); i++) {
39+
que.pop(nums[i - k]);
40+
que.push(nums[i]);
41+
result.push_back(que.front());
42+
}
43+
return result;
44+
}
45+
};
46+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## 题目地址
2+
3+
## 思路
4+
5+
6+
## C++代码
7+
```
8+
class Solution {
9+
public:
10+
class mycomparison {
11+
public:
12+
bool operator()(const pair<int, int>& lhs, const pair<int, int>& rhs) {
13+
return lhs.second < rhs.second;
14+
}
15+
};
16+
// 如何定义priQue
17+
// 如何定义cmp
18+
// 如何遍历map
19+
vector<int> topKFrequent(vector<int>& nums, int k) {
20+
unordered_map<int, int> map;
21+
for (int i = 0; i < nums.size(); i++) {
22+
map[nums[i]]++;
23+
}
24+
// greater<pair<int, int>> 也可以
25+
priority_queue<pair<int, int>, vector<pair<int, int>>, mycomparison> pri_que;
26+
27+
// 当然可以使用auto
28+
for (unordered_map<int, int>::iterator it = map.begin(); it != map.end(); it++) {
29+
pri_que.push(*it);
30+
}
31+
// 一开始就确定空间
32+
vector<int> result(k);
33+
for (int i = 0; i < k; i++) {
34+
result[i] = pri_que.top().first;
35+
pri_que.pop();
36+
}
37+
return result;
38+
39+
}
40+
};
41+
```

problems/0575.分糖果.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ https://leetcode-cn.com/problems/distribute-candies/
33

44
## 思路
55

6-
因为种类是可妹妹先来,所以思路先求出一共有多少种糖果,然后如果糖果种类大于candies的一半了,return candies的一半,否则,就是return 糖果的种类就可以了
6+
糖果的种类是可妹妹先来,所以思路先求出一共有多少种类型的糖果,需要注意: 数组中数字的大小也就是糖果的种类取值范围在[负十万和 正十万之间], 依然可以定义一个数组,通过哈希法求出有多少类型的糖果,那么糖果种类可以是负数 怎么办呢,可以把 定一个 20万大小的数组 ,就可以把糖果的全部类型映射到数组的下表了
77

8+
通过哈希法,可以求出了糖果的类型数量,如果糖果种类大于糖果总数的一半了,返回 糖果数量的一半就好,因为妹妹已经得到种类最多的糖果了,否则,就是返回 糖果的种类。
89

910
## 代码
1011

@@ -34,4 +35,6 @@ public:
3435
}
3536
};
3637
```
37-
> 笔者在先后在腾讯和百度从事技术研发多年,利用工作之余重刷leetcode,本文 [GitHub](https://github.com/youngyangyang04/leetcode-master )https://github.com/youngyangyang04/leetcode-master 已经收录,欢迎star,fork,共同学习,一起进步。
38+
39+
> 更过算法干货文章持续更新,可以微信搜索「代码随想录」第一时间围观,关注后,回复「Java」「C++」 「python」「简历模板」「数据结构与算法」等等,就可以获得我多年整理的学习资料。
40+

0 commit comments

Comments
 (0)