铃予 2022-05-04 13:53:56
因为父容器的宽度是600px,大于left跟right容器的宽度和,余100px,
没有margin跟padding影响,然后flex-grow的比是1:2,
所以left会多100 / 3 * 1 = 33.3的宽度,right会多100 / 3 * 2 = 66.7
最终left宽300 + 33.3 = 333.3,right宽200 + 66.7 = 266.7
铃予 2022-05-04 05:28:42
链表是一种物理存储单元上非连续、非顺序的存储结构,它既可以表示线性结构,也可以用于表示非线性结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。
使用链表结构可以克服数组链表需要预先知道数据大小的缺点,链表结构可以充分利用计算机内存空间,实现灵活的内存动态管理。
3.3 链表
3.3.1 单向链表
链表的最简单形式是单向链表,它的每个节点包含2部分:数据+指向下一节点的指针。最后一个节点指向NULL。
JavaScript实现
class Node { constructor(element) { this.element = element this.next = null } } class LinkedList { constructor() { this.head = null this.length = 0 } append(el) { const node = new Node(el) if (!this.head) { this.head = node } else { let current = this.head while (current.next) { current = current.next } current.next = node } this.length++ } insert(position, el) { if (position < 0 || position >= this.length) { return false } const node = new Node(el) if (position === 0) { node.next = this.head this.head = node } else { let current = this.head while (--position) { current = current.next } node.next = current.next current.next = node } this.length++ return true } indexOf(el) { let current = this.head let index = 0 while (current) { if (el === current.element) return index index++ current = current.next } return -1 } remove(el) { return this.removeAt(this.indexOf(el)) } removeAt(position) { if (position < 0 || position >= this.length) return false let current = this.head if (position === 0) { this.head = current.next } else { let index = 0 let previous while (index++ < position) { previous = current current = current.next } previous.next = current.next } current.next = null this.length-- return true } getHead() { return this.head } size() { return this.length } isEmpty() { return this.length === 0 } toString() { let res = '' let current = this.head while (current) { res += current.element current = current.next } return res } }
铃予 2022-05-03 00:14:29
补充一下:
extends 如果单纯用在ts类型系统中, 起到if
作用, 例如:
type DropChar< S extends string, C extends string > = S extends `${infer F}${infer R}` ? F extends C ? DropChar<R, C> : `${F}${DropChar<R, C>}` : S;
implements 后面 接的是 interface 用于 约束某一个类必须用哪一些属性, 方法
- 共 1 页
- 1
${num}*7
)第 102 题:不用加减乘除运算符,求整数的 7 倍