Skip to content

Commit

Permalink
feat: 电子书
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifer committed Oct 16, 2020
1 parent 86abd0c commit 386be21
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 429 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
.idea/*
_book/
.idea/*
node_modules/
5 changes: 5 additions & 0 deletions 91/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 91 天学算法

- [第一期讲义-二分法](.binary-search.md)
- [第一期讲义-双指针](./two-pointers.md)
- [第二期](.season2.md)
428 changes: 215 additions & 213 deletions SUMMARY.md

Large diffs are not rendered by default.

Binary file added book.epub
Binary file not shown.
2 changes: 1 addition & 1 deletion book.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"structure": {
"readme": "introduction.md"
},
"language": "zh-hans"

"plugins": ["page-toc"]
}
Binary file added book.mobi
Binary file not shown.
Binary file added book.pdf
Binary file not shown.
20 changes: 9 additions & 11 deletions introduction.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# LeetCode

[![Travis](https://img.shields.io/badge/language-C++-green.svg)]()
[![Travis](https://img.shields.io/badge/language-JavaScript-yellow.svg)]()
[![Travis](https://img.shields.io/badge/language-Python-red.svg)]()
[![Travis](https://img.shields.io/badge/language-Java-blue.svg)]()

[![](https://img.shields.io/badge/WeChat-微信群-brightgreen)](#关注我)
[![](https://img.shields.io/badge/公众号-力扣加加-blueviolet)](#关注我)
[![](https://img.shields.io/badge/Juejin-掘金-blue)](https://juejin.im/user/58af98305c497d0067780b3b)
[![](https://img.shields.io/badge/Zhihu-知乎-blue)](https://www.zhihu.com/people/lu-xiao-13-70)
[![](https://img.shields.io/badge/bilili-哔哩哔哩-ff69b4)](https://space.bilibili.com/519510412/)

简体中文 | [English](./README.en.md)

---
Expand All @@ -26,6 +15,14 @@

![](https://tva1.sinaimg.cn/large/007S8ZIlly1ghluemaoj3j30z90dtmy5.jpg)

## 前言

这是我将我的所有公开的算法资料整理的一个电子书,主要特点有:

- 全部题目信息中文化,以前会有一些英文描述。

后期可能将每日一题也整理进来。

## 介绍

leetcode 题解,记录自己的 leetcode 解题之路。
Expand Down Expand Up @@ -66,6 +63,7 @@ leetcode 题解,记录自己的 leetcode 解题之路。

## 食用指南

- 我对题目难度进行了分类的保留,因此你可以根据自己的情况刷。我推荐大家从简单开始,逐步加大难度,直到困难。
- 这里有一张互联网公司面试中经常考察的问题类型总结的思维导图,我们可以结合图片中的信息分析一下。

![leetcode-zhihu](https://tva1.sinaimg.cn/large/007S8ZIlly1ghluennxvrj30k00jx0te.jpg)
Expand Down
2 changes: 1 addition & 1 deletion problems/1.two-sum.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 题目地址
## 题目地址(1. 两数之和)

https://leetcode-cn.com/problems/two-sum

Expand Down
33 changes: 19 additions & 14 deletions problems/104.maximum-depth-of-binary-tree.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
## 题目地址
## 题目地址(104. 二叉树的最大深度)

https://leetcode.com/problems/maximum-depth-of-binary-tree/description/
https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/description/

## 题目描述

```
Given a binary tree, find its maximum depth.
给定一个二叉树,找出其最大深度。
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
Note: A leaf is a node with no children.
说明: 叶子节点是指没有子节点的节点。
Example:
Given binary tree [3,9,20,null,null,15,7],
示例:
给定二叉树 [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its depth = 3.
返回它的最大深度 3 。
```

Expand All @@ -45,7 +44,7 @@ return its depth = 3.
用递归实现的代码如下:

```js
var maxDepth = function(root) {
var maxDepth = function (root) {
if (!root) return 0;
if (!root.left && !root.right) return 1;
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
Expand All @@ -64,9 +63,11 @@ var maxDepth = function(root) {
- 树的基本操作- 遍历 - 层次遍历(BFS)

## 代码
* 语言支持:JS,C++,Python

- 语言支持:JS,C++,Python

JavaScript Code:

```js
/*
* @lc app=leetcode id=104 lang=javascript
Expand All @@ -84,7 +85,7 @@ JavaScript Code:
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
var maxDepth = function (root) {
if (!root) return 0;
if (!root.left && !root.right) return 1;

Expand All @@ -111,7 +112,9 @@ var maxDepth = function(root) {
return depth;
};
```

C++ Code:

```C++
/**
* Definition for a binary tree node.
Expand Down Expand Up @@ -147,6 +150,7 @@ public:
```
Python Code:
```python
class Solution:
def maxDepth(self, root: TreeNode) -> int:
Expand All @@ -164,16 +168,17 @@ class Solution:
```

**复杂度分析**

- 时间复杂度:$O(N)$
- 空间复杂度:$O(N)$

## 相关题目

- [102.binary-tree-level-order-traversal](./102.binary-tree-level-order-traversal.md)
- [103.binary-tree-zigzag-level-order-traversal](./103.binary-tree-zigzag-level-order-traversal.md)

更多题解可以访问我的LeetCode题解仓库https://github.com/azl397985856/leetcode 。 目前已经35K star啦
更多题解可以访问我的 LeetCode 题解仓库https://github.com/azl397985856/leetcode 。 目前已经 35K star 啦

关注公众号力扣加加,努力用清晰直白的语言还原解题思路,并且有大量图解,手把手教你识别套路,高效刷题。


![](https://tva1.sinaimg.cn/large/007S8ZIlly1gfcuzagjalj30p00dwabs.jpg)
61 changes: 32 additions & 29 deletions problems/121.best-time-to-buy-and-sell-stock.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
## 题目地址(121. 买卖股票的最佳时机)

## 题目地址
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/
https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/description/

## 题目描述

```
Say you have an array for which the ith element is the price of a given stock on day i.
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
如果你最多只允许完成一笔交易(即买入和卖出一支股票一次),设计一个算法来计算你所能获取的最大利润。
Note that you cannot sell a stock before you buy one.
注意:你不能在买入股票前卖出股票。
Example 1:
 
Input: [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Not 7-1 = 6, as selling price needs to be larger than buying price.
Example 2:
示例 1:
Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
输入: [7,1,5,3,6,4]
输出: 5
解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。
注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股票。
示例 2:
输入: [7,6,4,3,1]
输出: 0
解释: 在这种情况下, 没有交易完成, 所以最大利润为 0。
```

## 前置知识
Expand Down Expand Up @@ -65,23 +67,24 @@ JS Code:
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function(prices) {
let min = prices[0];
let profit = 0;
// 7 1 5 3 6 4
for(let i = 1; i < prices.length; i++) {
if (prices[i] > prices[i -1]) {
profit = Math.max(profit, prices[i] - min);
} else {
min = Math.min(min, prices[i]);;
}
var maxProfit = function (prices) {
let min = prices[0];
let profit = 0;
// 7 1 5 3 6 4
for (let i = 1; i < prices.length; i++) {
if (prices[i] > prices[i - 1]) {
profit = Math.max(profit, prices[i] - min);
} else {
min = Math.min(min, prices[i]);
}
}

return profit;
return profit;
};
```

C++ Code:

```c++
/**
* 系统上C++的测试用例中的输入有[],因此需要加一个判断
Expand All @@ -103,7 +106,9 @@ public:
}
};
```
Java Code:
```java
class Solution {
public int maxProfit(int[] prices) {
Expand Down Expand Up @@ -137,19 +142,17 @@ class Solution:
```

**复杂度分析**

- 时间复杂度:$O(N)$
- 空间复杂度:$O(1)$


## 相关题目

- [122.best-time-to-buy-and-sell-stock-ii](./122.best-time-to-buy-and-sell-stock-ii.md)
- [309.best-time-to-buy-and-sell-stock-with-cooldown](./309.best-time-to-buy-and-sell-stock-with-cooldown.md)


更多题解可以访问我的LeetCode题解仓库:https://github.com/azl397985856/leetcode 。 目前已经35K star啦。
更多题解可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 35K star 啦。

关注公众号力扣加加,努力用清晰直白的语言还原解题思路,并且有大量图解,手把手教你识别套路,高效刷题。


![](https://tva1.sinaimg.cn/large/007S8ZIlly1gfcuzagjalj30p00dwabs.jpg)
Loading

0 comments on commit 386be21

Please sign in to comment.