Skip to content

Commit

Permalink
feat: 算法相关文档新增固定链接,优化导入代码配置
Browse files Browse the repository at this point in the history
  • Loading branch information
142vip.cn committed Nov 7, 2023
1 parent 4c9515d commit 06596e7
Show file tree
Hide file tree
Showing 121 changed files with 370 additions and 638 deletions.
115 changes: 0 additions & 115 deletions code/algorithm/sword-point/Readme.md

This file was deleted.

9 changes: 2 additions & 7 deletions code/algorithm/sword-point/二分查找/getNumberOfK.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* 难度:中等
* @param data
* @param k
* @returns {number|number}
* @constructor
*/
function GetNumberOfK(data, k) {
// 分两次二分查找,知道重复元素首次和最后一次出现位置,相减就能拿到重复次数了.
Expand All @@ -19,6 +17,7 @@ function GetNumberOfK(data, k) {
return left === -1 && right === -1 ? 0 : right - left + 1
}

// 右侧二分查找
function rightBinarySearch(data, target) {
if (!data.length) {
return -1
Expand Down Expand Up @@ -47,7 +46,7 @@ function rightBinarySearch(data, target) {
return right
}

// [left,right]
// 左侧二分查找
function leftBinarySearch(data, target) {
if (!data.length) {
return -1
Expand Down Expand Up @@ -75,7 +74,3 @@ function leftBinarySearch(data, target) {
}
return left
}

module.exports = {
GetNumberOfK
}
6 changes: 0 additions & 6 deletions code/algorithm/sword-point/位运算/findNumsAppearOnce.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* 先排序,利用出现一次特性
* @param array
* @returns {*[]}
*/
function findNumsAppearOnceOne(array) {
// 数组中元素要么出现一次,要么出现两次,可以先对元素进行排序有点偷懒的样子
Expand Down Expand Up @@ -29,8 +27,6 @@ function findNumsAppearOnceOne(array) {

/**
* 利用Map统计出现次数
* @param array
* @returns {*[]}
*/
function findNumsAppearOnceTwo(array) {
const resMap = new Map()
Expand All @@ -56,8 +52,6 @@ function findNumsAppearOnceTwo(array) {

/**
* 利用异或运算
* @param array
* @returns {*[]}
*/
function findNumsAppearOnceThree(array) {
let res1 = 0
Expand Down
1 change: 0 additions & 1 deletion code/algorithm/sword-point/位运算/numberOf1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function NumberOf1(n) {
// 记录1的个数
let count = 0

// 循环验证
while (n !== 0) {
// 加+1 记录
Expand Down
3 changes: 0 additions & 3 deletions code/algorithm/sword-point/动态规划/fibonacci.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* 斐波那契数列,递归调用
* 难度:入门
* @param n
* @returns {*}
*/
function fibonacciOne(n) {
return n < 2 ? n : fibonacciOne(n - 1) + fibonacciOne(n - 2)
Expand All @@ -11,7 +9,6 @@ function fibonacciOne(n) {
/**
* 斐波那契数列,迭代
* 难度:入门
* @param n
*/
function fibonacciTwo(n) {
// 数列初始化
Expand Down
10 changes: 7 additions & 3 deletions code/algorithm/sword-point/动态规划/multiply.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/**
* 【简单】构建乘积数组
* @param array
* @returns {*[]}
*/
function multiply(array) {
const result = []

for (let index = 0; index < array.length; index++) {
// result.push(array.slice(0, index).reduce((res, item) => res * item, 1) * array.slice(index + 1).reduce((res, item) => res * item, 1))
// result
// .push(
// array
// .slice(0, index)
// .reduce((res, item) => res * item, 1) * array.slice(index + 1)
// .reduce((res, item) => res * item, 1)
// )
result.push([...array.slice(0, index), ...array.slice(index + 1)].reduce((res, item) => {
return res * item
}, 1)) // 给res的初始值为1
Expand Down
9 changes: 0 additions & 9 deletions code/algorithm/sword-point/链表/entryNodeOfLoop.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
* @Description:
* @Version: Beta1.0
* @Author: 【B站&公众号】储凡
* @Date: 2021-05-02 15:58:48
* @LastEditors: 【B站&公众号】储凡
* @LastEditTime: 2021-05-02 15:58:58
*/

function ListNode(x) {
this.val = x
this.next = null
Expand Down
11 changes: 0 additions & 11 deletions code/algorithm/sword-point/链表/findKthToTail.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
/*
* @Description:
* @Version: Beta1.0
* @Author: 【B站&公众号】储凡
* @Date: 2021-05-02 15:47:20
* @LastEditors: 【B站&公众号】储凡
* @LastEditTime: 2021-05-02 15:55:43
*/

function ListNode(x) {
this.val = x
this.next = null
}

/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param pHead ListNode类
* @param k int整型
* @return ListNode类
Expand Down
9 changes: 6 additions & 3 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import pluginsConfig from "./config/plugins.config";
import themeConfig from "./config/theme.config";
import {defineUserConfig, viteBundler} from "vuepress";
import {fileURLToPath} from 'node:url'
import {path} from "@vuepress/utils";
import {getDirname, path} from "@vuepress/utils";
// @ts-ignore
const __dirname = path.dirname(fileURLToPath(import.meta.url))

Expand Down Expand Up @@ -41,8 +41,11 @@ export default defineUserConfig({
if (str.includes('@code')) {
return str.replace(/^@code/, path.resolve(__dirname, '../../code/'))
}
if (str.includes('~@')) {
return str.replace(/^~@/, path.resolve(__dirname, '../../'))
if (str.includes('@algorithm')) {
return str.replace(/^@algorithm/, path.resolve(__dirname, '../../code/algorithm/'))
}
if (str.includes('~')) {
return str.replace(/^~/, path.resolve(__dirname, '../../'))
}
return str
},
Expand Down
1 change: 1 addition & 0 deletions docs/.vuepress/config/theme.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sidebar from "./sidebar";
import {AUTHOR_INFO, COPYRIGHT, FOOTER_HTML_INFO} from "./constant.config";
import {hopeTheme} from "vuepress-theme-hope";
import {langConfig} from "./lang.config";
import {path} from "@vuepress/utils";

/**
* 主题相关配置
Expand Down
6 changes: 3 additions & 3 deletions docs/manuscripts/develop-skill/code-style/engineering-lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pnpm install markdownlint-cli -D

在项目根目录新建`.markdownlint.js`文件,配置markdown的一些规则,例如:

@[code js](~@/.markdownlint.js)
@[code js](~/.markdownlint.js)

### 配置忽略

Expand All @@ -47,7 +47,7 @@ pnpm install markdownlint-cli -D

在项目根目录新建`.markdownlintignore`文件,配置markdown的忽略规则,例如:

@[code txt](~@/.markdownlintignore)
@[code txt](~/.markdownlintignore)

### 使用

Expand Down Expand Up @@ -115,7 +115,7 @@ pnpm install lint-staged -D

在项目根目录中新建`.lintstagedrc.js`文件

@[code js](~@/.lintstagedrc.js)
@[code js](~/.lintstagedrc.js)

以上规则是:

Expand Down
2 changes: 1 addition & 1 deletion docs/manuscripts/develop-skill/code-style/eslint.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pnpm i eslint -D

会自动生成`.eslintrc.js`文件,例如:

@[code js](~@/.eslintrc.js)
@[code js](~/.eslintrc.js)

其中`rules`对象可以自定义规则

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ permalink: /manuscripts/solo-algorithm/interview-101/fibonacci.html

## 代码实现

@[code js](@code/algorithm/interview-101/fibonacci.js)
@[code js](@algorithm/interview-101/fibonacci.js)

## 一些建议

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ permalink: /manuscripts/solo-algorithm/interview-101/jumpFloor.html

## 代码实现

@[code js](@code/algorithm/sword-point/动态规划/jumpFloor.js)
@[code js](@algorithm/sword-point/动态规划/jumpFloor.js)

## 一些建议

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ permalink: /manuscripts/solo-algorithm/interview-101/addList.html

## 代码实现

@[code js](@code/algorithm/interview-101/addInList.js)
@[code js](@algorithm/interview-101/addInList.js)

## 一些建议
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ permalink: /manuscripts/solo-algorithm/interview-101/deleteDuplicates-one.html

## 代码实现

@[code js](@code/algorithm/interview-101/deleteDuplicates-1.js)
@[code js](@algorithm/interview-101/deleteDuplicates-1.js)

## 一些建议
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ permalink: /manuscripts/solo-algorithm/interview-101/deleteDuplicates-two.html

## 代码实现

@[code js](@code/algorithm/interview-101/deleteDuplicates-2.js)
@[code js](@algorithm/interview-101/deleteDuplicates-2.js)

## 一些建议
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ permalink: /manuscripts/solo-algorithm/interview-101/entryNodeOfLoop.html

## 代码实现

@[code js](@code/algorithm/interview-101/entryNodeOfLoop.js)
@[code js](@algorithm/interview-101/entryNodeOfLoop.js)

## 一些建议
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ permalink: /manuscripts/solo-algorithm/interview-101/findFirstCommonNode.html

## 代码实现

@[code js](@code/algorithm/interview-101/findFirstCommonNode.js)
@[code js](@algorithm/interview-101/findFirstCommonNode.js)

## 一些建议
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ permalink: /manuscripts/solo-algorithm/interview-101/findKthToTail.html

## 代码实现

@[code js](@code/algorithm/interview-101/findKthToTail.js)
@[code js](@algorithm/interview-101/findKthToTail.js)

## 一些建议
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ permalink: /manuscripts/solo-algorithm/interview-101/hasCycle.html

## 代码实现

@[code js](@code/algorithm/interview-101/hasCycle.js)
@[code js](@algorithm/interview-101/hasCycle.js)

## 一些建议

0 comments on commit 06596e7

Please sign in to comment.