终陌 2022-05-04 13:56:27
看了前几个写的,随机生成的数组都是有重复值的,去重会减少数组长度不可取
const list = randInt(20, 10); // 1-20随机生成10个不重复的整数 group(list); function randInt(max, num) { const map = []; for (let i = 1; i <= max; i++) { map.push(i); } const res = []; for (let i = 0; i < num; i++) { const randIndex = Math.random() * (map.length - 1) + 1; res.push(map.splice(~~randIndex, 1)[0]); } return res; } function group(arr) { arr.sort(function (a, b) { return a - b; }); const res = []; for (const item of arr) { const index = ~~(item / 10); if (!res[index]) { res.push([]); } res[index].push(item); } return res; }
终陌 2022-05-04 13:55:49
dfs
const fn = (data, value) => { let res = [] const dfs = (arr, temp = []) => { for (const node of arr) { if (node.children) { dfs(node.children, temp.concat(node.id)) } else { if (node.id === value) { res = temp } return } } } dfs(data) return res }
为什么运行结果不对
- 共 1 页
- 1
tcp三次握手:
三次握手
数据传输
传输过程中,tcp连接会一次性发送若干个包测试连接速度,根据连接速度调整tcp包的发送频率
四次挥手
第 16 题:谈谈你对 TCP 三次握手和四次挥手的理解