Skip to content

Commit 1b78b01

Browse files
committed
feat: add tags
1 parent e6d4440 commit 1b78b01

Some content is hidden

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

52 files changed

+121
-14
lines changed

1_js_practice/async_filter.js 1_js_theory/async_filter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/* map version */
1+
// tags: #async #concurrence
22

3+
/* map version */
34
const asyncFilterByMap = async (arr, predicate) => {
45
const results = await Promise.all(arr.map(predicate));
56

1_js_practice/browser_fIle_hash.js 1_js_theory/browser_fIle_hash.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #hash #api
2+
13
// 使用浏览器 API 生成文件 SHA-256 哈希值
24
async function getFileHash() {
35
const [fileHandle] = await showOpenFilePicker();

1_js_practice/debounce.js 1_js_theory/debounce.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #debounce #closure #hot
2+
13
// 防抖
24
function debounce(fn, time) {
35
let timeout;

1_js_practice/deep_clone.js 1_js_theory/deep_clone.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #clone #recursion #hot
2+
13
function deepClone(obj, hash = new WeakMap()) {
24
if (obj instanceof Date) return new Date(obj);
35
if (obj instanceof RegExp) return new RegExp(obj);

1_js_practice/flat.js 1_js_theory/flat.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//tag: #flat #hot
2+
13
// 递归版本
24
function flattenByRecursion(arr) {
35
return arr.reduce((prev, next) => {

1_js_practice/get_value.js 1_js_theory/get_value.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #string #regex
2+
13
// writing a get function to pass test code below
24

35
// version 1

1_js_practice/inherits.js 1_js_theory/inherits.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #prototype #hot
2+
13
function inherits(Child, Parent) {
24
Child.prototype = Object.create(Parent.prototype);
35
Child.prototype.constructor = Child;

1_js_practice/limited_parallel.js 1_js_theory/limited_parallel.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #promise #concurrence
2+
13
/* 实现一个能够控制任务并发数量的函数 */
24
function limitedParallel(jobs, limit = 5) {
35
let cursor = limit;

1_js_practice/promise_all.js 1_js_theory/promise_all.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// tags: #promise #hot
2+
13
// 利用 Promise 实现 Promise.all 方法
24

5+
// tips:
36
// for in -> 数组、字符串、对象
47
// for of(可迭代对象) -> 数组、字符串、Map、Set
58
// forEach -> 数组、Map、Set

1_js_practice/promise_any.js 1_js_theory/promise_any.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #promise
2+
13
function _reverse(promise) {
24
return new Promise((resolve, reject) =>
35
Promise.resolve(promise).then(reject, resolve)

1_js_practice/promisify.js 1_js_theory/promisify.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #promise #callback
2+
13
function promisify(fn) {
24
return (...args) => {
35
return new Promise((res, rej) => {

1_js_practice/pubsub.js 1_js_theory/pubsub.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #event #design-mode #hot
2+
13
class PubSub {
24
#evts = {};
35

1_js_practice/rpc.js 1_js_theory/rpc.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #rpc #design-mode
2+
13
// 宿主环境提供线程通信 postMessage(message) 和 addListener((message)=>{}) 方法,封装他们进行 rpc 通讯
24
// 调用方式 const res = await rpc('method', ...params);
35

1_js_practice/throttle.js 1_js_theory/throttle.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #throttle #closure #hot
2+
13
// 截流
24
function throttle(fn, time) {
35
let canRun = true;

2_data_structure/bst.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #bst #data-structure
2+
13
// version 1
24
class BinarySearchTreeNode {
35
constructor(key, value) {

2_data_structure/graph.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// tags: #graph #data-structure
12
class DirectedGraph {
23
constructor() {
34
this._vertices = new Map();

2_data_structure/heap.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// #heap #priority-queue #data-structure
2+
13
// 堆有最大堆/最小堆, 可用于实现优先级队列、堆排序
24
class Heap {
35
#MAXHEAP;

2_data_structure/tree.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #tree #data-structure
2+
13
class Node {
24
constructor(val) {
35
this.val = val;

2_data_structure/trie.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #trie #data-structure
2+
13
class TrieNode {
24
constructor(char) {
35
this._char = char;

3_algorithm/big_positive_number_add.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #string #math
2+
13
// 大正数相加
24
// [link](../leetcode/415_add_strings.js)
35
function integerAdd(a, b) {

3_algorithm/bit_arithmetic.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #bit
2+
13
// 整数四则位运算
24

35
/*

3_algorithm/continuous_1.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #format
2+
13
// 输入是 1,2,3,5,7,8,10 输出要求是 1~3 5 7~8 10
24

35
function continuous(...args) {

3_algorithm/continuous_2.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #format
2+
13
// 将48位的时间位图格式化成字符串
24

35
// 要求:写一个函数timeBitmapToRanges,将下述规则描述的时间位图转换成一个选中时间区间的数组。

3_algorithm/excel_header.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #math #bit
2+
13
// question:循环A-Z当超过26个字母时输出AA...AZ...BA..
24

35
// A=0,Z=25,则任何进制下AA无法表示26

3_algorithm/knapsack_01.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #dp #knapsack
2+
13
// top-down
24
function knapsack01(weights, values, capacity) {
35
const memo = {};

3_algorithm/mid_numbers.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #monotonic-stack
2+
13
// 给出一个无序可有重复元素的数组,求数组中的所有满足其左边的数都小于它,右边的数都大于它的子元素
24

35
// verison 1

3_algorithm/split_coins.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #backtracking #combination
2+
13
/*
24
一堆硬币,面值可以是从1到500的任意整数,将他们分成两堆,求两堆面值总和的最小差值
35
比如 [3,4,5], 那么最小差值是 2

3_algorithm/topk.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #topk #quickselect
2+
13
// 快速选择
24
// time: O(N)
35
// space: O(N)

4_leetcode/100_same_tree.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #tree #dfs
2+
13
// https://leetcode.cn/problems/same-tree/
24

35
// time: 48ms | beat 99%

4_leetcode/104_maximum_depth_of_binary_tree.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #tree #dfs #backtracking #hot
2+
13
// https://leetcode.cn/problems/maximum-depth-of-binary-tree/
24

35
// version 1

4_leetcode/136_single_number.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #bit
2+
13
// https://leetcode.cn/problems/single-number/
24

35
// version 1

4_leetcode/144_binary_tree_preorder_traversal.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #tree #dfs
2+
13
// https://leetcode.cn/problems/binary-tree-preorder-traversal/
24

35
// 与常规遍历不同,用了原地分解问题思路

4_leetcode/15_3sum.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #hashmap #two-pointers
2+
13
// https://leetcode.cn/problems/3sum/
24

35
//三个版本都是 time O(n^2),在不断做常数项优化
@@ -33,7 +35,7 @@ var threeSum = function (nums) {
3335
const set = new Set();
3436
nums.sort((a, b) => a - b);
3537

36-
for (let i = nums.length; i >= 2; i--) {
38+
for (let i = nums.length - 1; i >= 2; i--) {
3739
j = 0;
3840
k = i - 1;
3941
while (j < k) {

4_leetcode/1_two_sum.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #hashmap
2+
13
// https://leetcode.cn/problems/two-sum/
24

35
// version 1

4_leetcode/206_reverse_linked_list.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #linkedlist #hot
2+
13
// https://leetcode.cn/problems/reverse-linked-list/
24

35
// version 1

4_leetcode/20_valid_parentheses.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #stack #hot
2+
13
// https://leetcode.cn/problems/valid-parentheses/
24

35
// time: O(n) | 52ms | beat 99%

4_leetcode/215_kth_largest_element_in_an_array.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #topk #quickselect
2+
13
// https://leetcode.cn/problems/kth-largest-element-in-an-array/
24

35
// version 1

4_leetcode/21_merge_two_sorted_lists.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #recursion #linkedlist #hot
2+
13
// https://leetcode.cn/problems/merge-two-sorted-lists/
24

35
// version 1

4_leetcode/26_remove_duplicates_from_sorted_array.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #two-pointers
2+
13
// https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
24

35
// time: O(n) | 72ms |beat 67%
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
// tags: #backtracking #combination #dp #LIS
2+
13
// https://leetcode.cn/problems/longest-increasing-subsequence/
24

35
// time: O(2^n) | TLE
4-
var lengthOfLIS = function(nums) {
6+
var lengthOfLIS = function (nums) {
57
let largest = [];
68
let current = [];
79

810
dfs(0);
911
return largest.length;
1012

1113
function dfs(start) {
12-
for (let i = start; nums.length - i > largest.length - current.length; i++) {
14+
for (
15+
let i = start;
16+
nums.length - i > largest.length - current.length;
17+
i++
18+
) {
1319
if (current.length !== 0 && nums[i] <= current.at(-1)) continue;
14-
current.push(nums[i])
20+
current.push(nums[i]);
1521
if (current.length > largest.length) largest = [...current];
1622
dfs(i + 1);
1723
current.pop();
@@ -20,7 +26,7 @@ var lengthOfLIS = function(nums) {
2026
};
2127

2228
// time: O(2^n) | 108ms | beat 79%
23-
var lengthOfLIS = function(nums) {
29+
var lengthOfLIS = function (nums) {
2430
const dp = [1];
2531
for (let i = 1; i < nums.length; i++) {
2632
let max = 0;
@@ -29,5 +35,5 @@ var lengthOfLIS = function(nums) {
2935
}
3036
dp[i] = max + 1;
3137
}
32-
return Math.max(...dp)
33-
}
38+
return Math.max(...dp);
39+
};

4_leetcode/322_coin_change.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #dp #knapsack
2+
13
// https://leetcode.cn/problems/coin-change/
24

35
// version 1

4_leetcode/344_reverse_string.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #string
2+
13
// https://leetcode.cn/problems/reverse-string/
24

35
// 实现数组 reverse 方法

4_leetcode/349_intersection_of_two_arrays.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #hashmap
2+
13
// https://leetcode.cn/problems/intersection-of-two-arrays/
24

35
// version 1

4_leetcode/354_russian_doll_envelopes.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #dp #LIS
2+
13
// https://leetcode.cn/problems/russian-doll-envelopes/
24

35
// time: O(n^2) | TLE

4_leetcode/384_shuffle_an_array.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #math
2+
13
// https://leetcode.cn/problems/shuffle-an-array/
24

35
var Solution = function (nums) {

4_leetcode/415_add_strings.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #math
2+
13
// https://leetcode.cn/problems/add-strings/
24

35
// time: 68ms | beat 68%

4_leetcode/42_trapping_rain_water.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #two-pointers
2+
13
// https://leetcode.cn/problems/trapping-rain-water/
24

35
// version 1

4_leetcode/46_permutations.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #backtracking #permutation
2+
13
// https://leetcode.cn/problems/permutations/
24

35
// time: O(n!) | 80ms | beat 33%

4_leetcode/51_n_queens.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #backtracking
2+
13
// https://leetcode.cn/problems/n-queens/
24

35
// time: 76ms | beat 66%

4_leetcode/70_climbing_stairs.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #dp #hot
2+
13
// https://leetcode.cn/problems/climbing-stairs/
24

35
// version 1

4_leetcode/77_combinations.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// tags: #backtracking #combination
2+
13
// https://leetcode.cn/problems/combinations/
24

35
// 排列每层都重头找,组合下层从上一层的下一个开始找

README.md

+8-6

0 commit comments

Comments
 (0)