1.基础
1.1.时间复杂度、空间复杂度
2.八大数据结构
2.1.栈
力扣:
20,有效的括号
71,简化路径
155,最小栈
392. 判断子序列
拓展:
496,下一个更大元素
2.2.队列
const queue = []
queue.push(0)
queue.push(1)
queue.push(2)
const res = queue.shift()
console.log(res)
2.3.链表
2.4集合
const arr = [1, 1, 2, 2]
const set = [...new Set(arr)]
const arr = [1, 1, 2, 2]
const set = new Set(arr)
const res = set.has(3)
console.log(res)
const set1 = [...new Set([1, 2])]
const set2 = new Set([1, 3])
const newSet = new Set(set1.filter((e) => set2.has(e)))
2.5.字典(哈希)
const m1 = new Map()
m1.set("key1", "value1")
m1.set("key2", "value2")
m1.set("key3", "value3")
m1.delete("key1")
m1.set("key2", "v2")
const res = m1.get("key2")
2.6.树
2.7.图
2.8.堆
3.
力扣
1.赎金信
var canConstruct = function (ransomNote, magazine) {
const map = new Array(26).fill(0)
if (magazine.length < ransomNote.length) return false
for (const iterator of magazine) {
map[iterator.charCodeAt() - "a".charCodeAt()]++
}
for (const iterator of ransomNote) {
map[iterator.charCodeAt() - "a".charCodeAt()]--
if (map[iterator.charCodeAt() - "a".charCodeAt()] < 0) {
return false
}
}
return true
}
2.两数之和,有序数列
var twoSum = function (numbers, target) {
let left = 0
let right = numbers.length - 1
while (true) {
let t = numbers[left] + numbers[right]
if (t === target) {
return [left + 1, right + 1]
}
t > target ? right-- : left++
}
};
3.