随笔分类 - 数据结构与算法
摘要:```js // 最大公约数算法 // 1. a % b 进行取余运算 // 2. 将被取余数与余数进行再次取余运算 // 3. 直到a % b为0时停止取余运算 // 4. 将取余为0时的被取余数返回即是最大公约数 function gcd(a, b) { if (b === 0) { return a; } return gcd(b, a % b); }// 求多...
阅读全文
摘要:bitmap实现原理 add操作 js //得到第几行索引 let byteIndex = Math.floor(k / 16); //得到第几列的索引 let bitIndex = k % 16; //将1移动到索引的位置并修改该位置 this.blk[byteIndex] = this.blk[
阅读全文
摘要:simhash 在simhash中处理一个文本的步骤如下: 第一步,分词: 对文本进行分词操作,同时需要我们同时返回当前词组在文本内容中的权重(这基本上是目前所有分词工具都支持的功能)。 第二步,计算hash: 对于每一个得到的词组做hash,将词语表示为到01表示的bit位,需要保证每个hash结
阅读全文
摘要:计算当前日期星座 | 起始月份 | 号数| 星座 | 结束月份 | 号数 | 时间区间| | | | | | | | | 12 | 22 | 摩羯座 | 1 | 19 | 12/22 1/19| | 1 | 20 | 水瓶座 | 2 | 18 | 1/20 2/18 | | 2 | 19 | 双鱼座
阅读全文
摘要:数独 游戏规则 检查算法 数独自动求解 js const NOTASIGN = 0 function usedInCol(map,row,num){ for(let col = 0; col
阅读全文
摘要:迷宫找出口 js function isSafe(maze,x,y){ if(x = 0 && y = 0 && x
阅读全文
摘要:初始化地图 js function initMaze(r,c){ let row = new Array(2 r + 1) for(let i = 0; i { const visited = [], key = [], parent = []; let {length} = graph; for(
阅读全文
摘要:```js
class TrieNode { constructor(data){ this.data = data this.children = new Array(26) this.isEndingChar = false this.text = '' }
} class TrieTree { cons...
阅读全文
摘要:AC自动机 js class ACNode { constructor(data){ this.data = data this.isEndingChar = false this.children = new Map() this.length = 0 this.fail = null } } c
阅读全文
摘要:最短编辑距离 js function levenshteinDistance(a,b){ //生成表 const distanceMatix = Array(a.length + 1).fill(null).map(() = Array(b.length + 1).fill(null)) //第一行
阅读全文
摘要:朴素匹配算法 KMP算法 字符串前后缀 字符关系 执行过程 js //i指针不必回溯 //next[j]表示回溯位置 / 规则1:没有公共前后缀的情况,匹配失败时j = 0去匹配 s: a b (c) d e f g t: a b (d) t串中a与后边的bd串都不相等,在d匹配c失败时,可以知道t
阅读全文
摘要:创建队列 使用ES6改造 最小优先队列 js function PriorityQueue(){ let items = [] function QueueElement(element,priority){ this.element = element this.priority = priori
阅读全文
摘要:实现栈结构 ES6改造 进制转换 平衡圆括号 js function balancedSymbols(symbols){ const stack = new Stack() const opens = const closers = let balanced = true let index = 0
阅读全文

浙公网安备 33010602011771号