Skip to content

Commit 06596e7

Browse files
author
142vip.cn
committed
feat: 算法相关文档新增固定链接,优化导入代码配置
1 parent 4c9515d commit 06596e7

File tree

121 files changed

+370
-638
lines changed

Some content is hidden

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

121 files changed

+370
-638
lines changed

code/algorithm/sword-point/Readme.md

Lines changed: 0 additions & 115 deletions
This file was deleted.

code/algorithm/sword-point/二分查找/getNumberOfK.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* 难度:中等
44
* @param data
55
* @param k
6-
* @returns {number|number}
7-
* @constructor
86
*/
97
function GetNumberOfK(data, k) {
108
// 分两次二分查找,知道重复元素首次和最后一次出现位置,相减就能拿到重复次数了.
@@ -19,6 +17,7 @@ function GetNumberOfK(data, k) {
1917
return left === -1 && right === -1 ? 0 : right - left + 1
2018
}
2119

20+
// 右侧二分查找
2221
function rightBinarySearch(data, target) {
2322
if (!data.length) {
2423
return -1
@@ -47,7 +46,7 @@ function rightBinarySearch(data, target) {
4746
return right
4847
}
4948

50-
// [left,right]
49+
// 左侧二分查找
5150
function leftBinarySearch(data, target) {
5251
if (!data.length) {
5352
return -1
@@ -75,7 +74,3 @@ function leftBinarySearch(data, target) {
7574
}
7675
return left
7776
}
78-
79-
module.exports = {
80-
GetNumberOfK
81-
}

code/algorithm/sword-point/位运算/findNumsAppearOnce.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* 先排序,利用出现一次特性
3-
* @param array
4-
* @returns {*[]}
53
*/
64
function findNumsAppearOnceOne(array) {
75
// 数组中元素要么出现一次,要么出现两次,可以先对元素进行排序有点偷懒的样子
@@ -29,8 +27,6 @@ function findNumsAppearOnceOne(array) {
2927

3028
/**
3129
* 利用Map统计出现次数
32-
* @param array
33-
* @returns {*[]}
3430
*/
3531
function findNumsAppearOnceTwo(array) {
3632
const resMap = new Map()
@@ -56,8 +52,6 @@ function findNumsAppearOnceTwo(array) {
5652

5753
/**
5854
* 利用异或运算
59-
* @param array
60-
* @returns {*[]}
6155
*/
6256
function findNumsAppearOnceThree(array) {
6357
let res1 = 0

code/algorithm/sword-point/位运算/numberOf1.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
function NumberOf1(n) {
22
// 记录1的个数
33
let count = 0
4-
54
// 循环验证
65
while (n !== 0) {
76
// 加+1 记录

code/algorithm/sword-point/动态规划/fibonacci.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* 斐波那契数列,递归调用
33
* 难度:入门
4-
* @param n
5-
* @returns {*}
64
*/
75
function fibonacciOne(n) {
86
return n < 2 ? n : fibonacciOne(n - 1) + fibonacciOne(n - 2)
@@ -11,7 +9,6 @@ function fibonacciOne(n) {
119
/**
1210
* 斐波那契数列,迭代
1311
* 难度:入门
14-
* @param n
1512
*/
1613
function fibonacciTwo(n) {
1714
// 数列初始化

code/algorithm/sword-point/动态规划/multiply.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
/**
22
* 【简单】构建乘积数组
3-
* @param array
4-
* @returns {*[]}
53
*/
64
function multiply(array) {
75
const result = []
86

97
for (let index = 0; index < array.length; index++) {
10-
// result.push(array.slice(0, index).reduce((res, item) => res * item, 1) * array.slice(index + 1).reduce((res, item) => res * item, 1))
8+
// result
9+
// .push(
10+
// array
11+
// .slice(0, index)
12+
// .reduce((res, item) => res * item, 1) * array.slice(index + 1)
13+
// .reduce((res, item) => res * item, 1)
14+
// )
1115
result.push([...array.slice(0, index), ...array.slice(index + 1)].reduce((res, item) => {
1216
return res * item
1317
}, 1)) // 给res的初始值为1

code/algorithm/sword-point/链表/entryNodeOfLoop.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* @Description:
3-
* @Version: Beta1.0
4-
* @Author: 【B站&公众号】储凡
5-
* @Date: 2021-05-02 15:58:48
6-
* @LastEditors: 【B站&公众号】储凡
7-
* @LastEditTime: 2021-05-02 15:58:58
8-
*/
9-
101
function ListNode(x) {
112
this.val = x
123
this.next = null

code/algorithm/sword-point/链表/findKthToTail.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
/*
2-
* @Description:
3-
* @Version: Beta1.0
4-
* @Author: 【B站&公众号】储凡
5-
* @Date: 2021-05-02 15:47:20
6-
* @LastEditors: 【B站&公众号】储凡
7-
* @LastEditTime: 2021-05-02 15:55:43
8-
*/
9-
101
function ListNode(x) {
112
this.val = x
123
this.next = null
134
}
145

156
/**
167
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
17-
*
18-
*
198
* @param pHead ListNode类
209
* @param k int整型
2110
* @return ListNode类

docs/.vuepress/config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import pluginsConfig from "./config/plugins.config";
22
import themeConfig from "./config/theme.config";
33
import {defineUserConfig, viteBundler} from "vuepress";
44
import {fileURLToPath} from 'node:url'
5-
import {path} from "@vuepress/utils";
5+
import {getDirname, path} from "@vuepress/utils";
66
// @ts-ignore
77
const __dirname = path.dirname(fileURLToPath(import.meta.url))
88

@@ -41,8 +41,11 @@ export default defineUserConfig({
4141
if (str.includes('@code')) {
4242
return str.replace(/^@code/, path.resolve(__dirname, '../../code/'))
4343
}
44-
if (str.includes('~@')) {
45-
return str.replace(/^~@/, path.resolve(__dirname, '../../'))
44+
if (str.includes('@algorithm')) {
45+
return str.replace(/^@algorithm/, path.resolve(__dirname, '../../code/algorithm/'))
46+
}
47+
if (str.includes('~')) {
48+
return str.replace(/^~/, path.resolve(__dirname, '../../'))
4649
}
4750
return str
4851
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import sidebar from "./sidebar";
33
import {AUTHOR_INFO, COPYRIGHT, FOOTER_HTML_INFO} from "./constant.config";
44
import {hopeTheme} from "vuepress-theme-hope";
55
import {langConfig} from "./lang.config";
6+
import {path} from "@vuepress/utils";
67

78
/**
89
* 主题相关配置

0 commit comments

Comments
 (0)