Skip to content

Commit 9b8cec4

Browse files
author
xing dali
committed
2 parents 5525a10 + 13d7ce6 commit 9b8cec4

File tree

9 files changed

+54
-30
lines changed

9 files changed

+54
-30
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@
77
## 在线阅读
88

99
本算法模板主要参考自[greyireland](https://github.com/greyireland)[algorithm-pattern](https://github.com/greyireland/algorithm-pattern)项目,将其Go语言代码翻译成JavaScript语言代码。
10+
11+
## 核心内容
12+
13+
#### 数据结构篇 🐢
14+
15+
- [二叉树](https://github.com/ligecarryme/algorithm-pattern-JavaScript/blob/master/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AF%87/%E4%BA%8C%E5%8F%89%E6%A0%91.md)

入门(Java)/力扣经典算法.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ char[] chars = s.toCharArray();
2020
Pattern.matchs() // 字符串匹配
2121
```
2222

23-
24-
2523
### 动态规划
2624

2725
**第一步骤**:定义**数组元素的含义**,我们会用一个数组,来保存历史数组,假设用一维数组 dp[] 吧。这个时候有一个非常非常重要的点,就是规定你这个数组元素的含义,例如你的 dp[i] 是代表什么意思。

基础算法篇/二分搜索.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
### 二分搜索
1+
## 二分搜索
22

3-
#### 二分搜索模板
3+
### 二分搜索模板
44

55
给一个**有序数组**和目标值,找第一次/最后一次/任何一次出现的索引,如果没有出现返回 -1
66

基础算法篇/动态规划.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
### 动态规划
1+
# 动态规划
22

3-
#### 背景
3+
## 背景
44

55
先从一道题目开始~
66

数据结构篇/二叉树.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
### 二叉树
1+
## 二叉树
22

3-
#### 二叉树遍历
3+
### 二叉树遍历
44

55
**前序遍历****先访问根节点**,再前序遍历左子树,再前序遍历右子树 **中序遍历**:先中序遍历左子树,**再访问根节点**,再中序遍历右子树 **后序遍历**:先后序遍历左子树,再后序遍历右子树,**再访问根节点**
66

@@ -457,3 +457,21 @@ const helper = (node, smaller, bigger) => {
457457
}
458458
```
459459

460+
[701. 二叉搜索树中的插入操作](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/)
461+
462+
给定二叉搜索树(BST)的根节点和要插入树中的值,将值插入二叉搜索树。 返回插入后二叉搜索树的根节点。 输入数据 保证 ,新值和原始二叉搜索树中的任意节点值都不同。
463+
464+
```js
465+
var insertIntoBST = function (root, val) {
466+
if (root === null) {
467+
return new TreeNode(val)
468+
}
469+
if (root.val > val) {
470+
root.left = insertIntoBST(root.left, val)
471+
} else {
472+
root.right = insertIntoBST(root.right, val)
473+
}
474+
return root
475+
};
476+
```
477+

数据结构篇/二进制.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### 二进制
1+
## 二进制
22

33
JS二进制基础知识: [二进制](https://wangdoc.com/javascript/operators/bit.html)
44

数据结构篇/栈和队列.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
### 栈和队列
1+
## 栈和队列
22

3-
#### 简介
3+
### 简介
44

55
栈的特点是后入先出,根据这个特点可以临时保存一些数据,之后用到依次再弹出来,常用于 DFS 深度搜索
66

77
队列一般常用于 BFS 广度搜索,类似一层一层的搜索。
88

9-
#### Stack 栈
9+
### Stack 栈
1010

1111
##### 155.最小栈 [min-stack](https://leetcode-cn.com/problems/min-stack/)
1212

数据结构篇/链表.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
### 链表
1+
## 链表
22

3-
#### 核心点
3+
### 核心点
44

55
- null/nil 异常处理
66
- dummy node 哑巴节点
@@ -11,21 +11,25 @@
1111
- 合并两个链表
1212
- 找到链表的中间节点
1313

14-
#### 练习
15-
16-
##### 83.删除排序链表中的重复元素 [remove-duplicates-from-sorted-list](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/)
17-
18-
> 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
14+
**链表的数据结构**
1915

2016
```js
2117
/**
2218
* Definition for singly-linked list.
23-
* function ListNode(val) {
24-
* this.val = val;
25-
* this.next = null;
26-
* }
2719
*/
20+
function ListNode(val) {
21+
this.val = val;
22+
this.next = null;
23+
}
24+
```
25+
26+
### 练习
2827

28+
##### 83.删除排序链表中的重复元素 [remove-duplicates-from-sorted-list](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/)
29+
30+
> 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
31+
32+
```js
2933
var deleteDuplicates = function(head) {
3034
let current = head;
3135
while(current !== null && current.next !== null){
@@ -39,10 +43,8 @@ var deleteDuplicates = function(head) {
3943
};
4044
```
4145

42-
递归写法
43-
4446
```js
45-
var deleteDuplicates = function(head) {
47+
var deleteDuplicates = function(head) { // 递归写法
4648
if(head === null || head.next === null){
4749
return head;
4850
}
@@ -69,7 +71,7 @@ var deleteDuplicates = function(head) {
6971
front = front.next;
7072
back = back.next;
7173
} else {
72-
while(back!==null && front.next.val === back.val){
74+
while(back !== null && front.next.val === back.val){
7375
back = back.next;
7476
}
7577
front.next = back;

算法思维/递归思维.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
### 递归
1+
## 递归
22

3-
#### 介绍
3+
### 介绍
44

55
将大问题转化为小问题,通过递归依次解决各个小问题。
66

7-
#### 示例
7+
### 示例
88

99
##### 334.反转字符串 [reverse-string](https://leetcode-cn.com/problems/reverse-string/)
1010

0 commit comments

Comments
 (0)