Skip to content

Commit 1c24993

Browse files
author
Chu Fan
committed
feat: 新增一些文档,优化配置
- 新增shell文档 - 剑指题目更新
1 parent 3251a00 commit 1c24993

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1052
-177
lines changed

code/algorithm/剑指/数组和矩阵/printMatrix.js

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
* @LastEditTime: 2021-04-28 22:25:16
88
*/
99

10-
function printMatrix(matrix) {
10+
11+
/**
12+
* 没有技巧,按照方向转
13+
* @param matrix
14+
* @returns {*[]}
15+
*/
16+
function printMatrixOne(matrix) {
1117
// 行 角标
1218
let row = matrix.length - 1
1319
// 列角标
@@ -62,7 +68,50 @@ function printMatrix(matrix) {
6268
return result
6369
}
6470

65-
console.log(printMatrix([
66-
[1, 2],
67-
[3, 4]
68-
]))
71+
/**
72+
* 利用一些特性和api
73+
* @param matrix
74+
* @returns {*[]}
75+
*/
76+
function printMatrixTwo(matrix) {
77+
const len = matrix.length
78+
if (len === 1) return [...matrix[0]]
79+
80+
let seq = []
81+
for (let i = 0; i < matrix.length / 2; i++) {
82+
// 元素平铺为一维
83+
seq.push(...matrix.shift())
84+
85+
for (const row of matrix) {
86+
seq.push(row.pop())
87+
}
88+
89+
if (matrix.length === 0) break
90+
else seq.push(...matrix.pop().reverse())
91+
92+
// 左侧 从下网上aa'a's'd'fa's'da's'd'fa's'da's'd'fa's'd
93+
const leftResult = []
94+
for (const row of matrix) {
95+
leftResult.push(row.shift())
96+
}
97+
seq = seq.concat(leftResult.reverse())
98+
}
99+
100+
// 过滤
101+
return seq.filter(x => x != null)
102+
}
103+
104+
console.log(printMatrixOne([
105+
[1, 2, 3, 4],
106+
[5, 6, 7, 8],
107+
[9, 10, 11, 12],
108+
[13, 14, 15, 16]]
109+
))
110+
111+
console.log(printMatrixTwo([
112+
[1, 2, 3, 4],
113+
[5, 6, 7, 8],
114+
[9, 10, 11, 12],
115+
[13, 14, 15, 16]]
116+
))
117+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* @Description: 最小的K个数
3+
* @Version: Beta1.0
4+
* @Author: 【B站&公众号】Rong姐姐好可爱
5+
* @Date: 2021-04-28 23:12:33
6+
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
7+
* @LastEditTime: 2021-04-28 23:35:30
8+
*/
9+
10+
/**
11+
* 先排序,后截取(偷懒做法)
12+
*
13+
* @param input
14+
* @param k
15+
* @returns {*}
16+
*/
17+
function getLeastNumbersOne(input, k) {
18+
// 直接基于快排,最快速的拿到排序结果也行
19+
return input.sort((a, b) => a - b).slice(0, k)
20+
}
21+
22+
/**
23+
* 基于冒泡排序,跑K趟即可
24+
* @param input
25+
* @param k
26+
* @returns {*[]|*}
27+
*/
28+
function getLeastNumbersTwo(input, k) {
29+
const len = input.length
30+
// 添加参数校验
31+
if (k > len) {
32+
return []
33+
}
34+
// 先将输入的数组进行排序从小到大 只排前面几个即可
35+
// 这里首先想到的是冒泡或者插入排序里面的特性 --- 每次都有一个元素在最终的位置上
36+
37+
// 循环k次,跑k趟
38+
for (let index = 0; index < k; index++) {
39+
// 从后往前找
40+
for (let j = len - 1; j > index; j--) {
41+
if (input[index] > input[j]) {
42+
// 找到比它小的,位置交换
43+
[input[index], input[j]] = [input[j], input[index]]
44+
}
45+
}
46+
}
47+
// 排序完毕,输入前k个
48+
return input.slice(0, k)
49+
}
50+
51+
/**
52+
* 基于选择排序
53+
* @param input
54+
* @param k
55+
*/
56+
function getLeastNumbersThree(input, k) {
57+
const len = input.length
58+
for (let i = 0; i < k; i++) {
59+
// 从前往后找
60+
for (let j = i; j < len; j++) {
61+
if (input[i] > input[j]) {
62+
// 位置互换,从小到大
63+
[input[i], input[j]] = [input[j], input[i]]
64+
}
65+
}
66+
}
67+
68+
// 找出前k个
69+
return input.slice(0, k)
70+
}
71+
72+
73+
/**
74+
* 基于堆排序
75+
* @param input
76+
* @param k
77+
*/
78+
function getLeastNumbersFour(input, k) {
79+
// todo 构建树 维护小根堆
80+
}
81+
82+
83+
console.log(getLeastNumbersOne([4, 5, 1, 6, 2, 7, 3, 8], 4))
84+
console.log(getLeastNumbersTwo([4, 5, 1, 6, 2, 7, 3, 8], 4))
85+
console.log(getLeastNumbersThree([4, 5, 1, 6, 2, 7, 3, 8], 4))

code/algorithm/剑指/栈队列堆/getLeastNumbersSolution.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,27 @@
88
*/
99

1010
const result = []
11+
12+
/**
13+
* 模拟进队列操作
14+
* @param node
15+
* @returns {*[]}
16+
*/
1117
function push(node) {
1218
// 尾部进栈
1319
result.push(node)
20+
return result
1421
}
22+
23+
/**
24+
* 模拟出队列操作
25+
* @returns {*}
26+
*/
1527
function pop() {
1628
// 队列 先进先出 头部出去
1729
return result.shift()
1830
}
31+
32+
33+
console.log(push(1), push(2))
34+
console.log(pop(), pop())

docs/.vuepress/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {defineClientConfig} from '@vuepress/client'
22
// import NotFound from './layouts/NotFound.vue'
3-
import {onMounted} from 'vue'
3+
// import {onMounted} from 'vue'
44

55
export default defineClientConfig({
66
enhance({app, router, siteData}) {
77
},
8-
setup() {
9-
onMounted(() => {
10-
// 在 mounted 之后使用 DOM API
11-
document.querySelector('#app')
12-
})
13-
},
8+
// setup() {
9+
// onMounted(() => {
10+
// // 在 mounted 之后使用 DOM API
11+
// document.querySelector('#app')
12+
// })
13+
// },
1414
layouts: {},
1515
rootComponents: [],
1616
})

docs/.vuepress/config/theme.config.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export default {
1919
// pure: true,
2020
hostname: 'https://408.142vip.cn',
2121
author: {
22-
name: '储凡',
23-
email: 'fairy_408@2925.com',
22+
name: '公众号:储凡',
23+
email: 'fairy_vip@2925.com',
2424
url: 'https://www.142vip.cn'
2525
},
2626
favicon: "/favicon.ico",
@@ -138,15 +138,19 @@ export default {
138138
notice: [
139139
{
140140
path: "/",
141-
title: "公告测试",
142-
content: "Notice Content",
141+
title: "在线浏览",
142+
content: "网站无法访问时,建议通过科学上网访问备用网络",
143143
actions: [
144144
{
145-
text: "跳转链接",
146-
link: "https://theme-hope.vuejs.press/",
145+
text: "尝鲜版",
146+
link: "https://142vip.github.io/JavaScriptCollection",
147+
type: "default",
148+
},
149+
{
150+
text: "稳定版",
151+
link: "https://142vip.cn/JavaScriptCollection",
147152
type: "primary",
148153
},
149-
{text: "默认按钮"},
150154
],
151155
fullscreen: false,
152156
},

docs/manuscript/solo-algorithm/shell/readme.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11

2-
# SHELL篇刷题
2+
# SHELL篇
33

44

5+
### 基础
6+
7+
8+
### 刷题
9+
510
- [x] [SHELL-1 统计文件的行数【简单】](shell-1.md)
611
- [ ] [SHELL-2 打印文件的最后5行【简单】](shell-2.md)
712
- [ ] [SHELL-3 输出7的倍数【中等】](shell-3.md)
813
- [ ] [SHELL-4 输出第5行的内容【中等】](shell-4.md)
914
- [ ] [SHELL-5 打印空行的行号【中等】](shell-5.md)
1015
- [ ] [SHELL-6 去掉空行【中等】](shell-6.md)
11-
- [ ] [SHELL-7 打印字母数小于8的单词 【较难】](shell-1.md)
12-
- [ ] [SHELL-8 统计所有进程占用内存大小的和 【较难】](shell-1.md)
13-
- [ ] [SHELL-9 统计每个单词出现的个数 【较难】](shell-1.md)
16+
- [ ] [SHELL-7 打印字母数小于8的单词 【较难】](shell-7.md)
17+
- [ ] [SHELL-8 统计所有进程占用内存大小的和 【较难】](shell-8.md)
18+
- [ ] [SHELL-9 统计每个单词出现的个数 【较难】](shell-9.md)
1419
- [ ] [SHELL-10 第二列是否有重复 【较难】](shell-1.md)
1520
- [ ] [SHELL-11 转置文件的内容 【较难】](shell-1.md)
1621
- [ ] [SHELL-12 打印每一行出现的数字个数 【较难】](shell-1.md)
@@ -36,3 +41,6 @@
3641
- [ ] [SHELL-32 netstat练习4-输出和3306端口建立连接总的各个状态的数目 【较难】](shell-32.md)
3742
- [ ] [SHELL-33 业务分析-提取值 【中等】](shell-33.md)
3843
- [ ] [SHELL-34 ps分析-统计VSZ,RSS各自总和 【中等】](shell-34.md)
44+
45+
46+
### 参考资料

docs/manuscript/solo-algorithm/shell/shell-1.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
描述
1111
编写一个shell脚本以输出一个文本文件nowcoder.txt中的行数
12+
1213
示例:
1314
假设 nowcoder.txt 内容如下:
1415
```txt
@@ -28,7 +29,7 @@ int main()
2829

2930
### 代码实现
3031

31-
@[code js](@code/algorithm/剑指/数组和矩阵/FirstNotRepeatingChar.js)
32+
@[code bash](@code/algorithm/shell/shell-1.sh)
3233

3334

3435
### 一些建议
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 算法相关文档格式模版
2+
3+
4+
5+
6+
### 题目链接
7+
8+
- [牛客网]()
9+
- [欢迎讨论]()
10+
11+
### 题目描述
12+
13+
14+
### 思路
15+
16+
### 代码实现
17+
18+
19+
@[code bash](@code/algorithm/shell/shell-1.sh)
20+
21+
22+
### 一些建议
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 算法相关文档格式模版
2+
3+
4+
5+
6+
### 题目链接
7+
8+
- [牛客网]()
9+
- [欢迎讨论]()
10+
11+
### 题目描述
12+
13+
14+
### 思路
15+
16+
### 代码实现
17+
18+
19+
@[code bash](@code/algorithm/shell/shell-1.sh)
20+
21+
22+
### 一些建议

0 commit comments

Comments
 (0)