算法
- 这是一个函数条件二分
- 先对 nums 进行排序,这样就可以求出最大距离 right = nums[len - 1] - nums[0] 和最小的距离 left=0
- 使用二分法,设置一个中间值 mid,找出小于等于 mid 的距离对数量 count
- 比对count 和 k,如果 count < k, 证明第 k 小的距离值比 mid 大,所以 left = mid + 1
- 如果count === k 的时候,由于找的是第 k 小,所以可能存在值小于 mid,但是 count 也等于 k 的情况,所以也要归咎于 right = mid-1
- 最后 返回 left
二维矩阵

/*** @param {number} n* @return {number[][]}*/var generateMatrix = function(n) {let [startX, startY] = [0, 0];let loop = n >> 1; // 旋转圈数let mid = n >> 1; // 中间位置需要单独处理let res = new Array(n).fill(0).map(() => new Array(n).fill(0));let newNum = 1; // n 在每一层需要减去的数字let count = 1;while(loop--){let row = startX, col = startY;// 上,左闭右开for(; col < startY + n - newNum; col++){res[row][col] = count;count++;}// 右,左闭右开for(; row < startX + n - newNum; row++){res[row][col] = count;count++;}// 下,左闭右开for(; col > startY; col--){res[row][col] = count;count++;}// 左,左闭右开for(; row > startX; row--){res[row][col] = count;count++;}// 更新startX++, startY++;newNum += 2;}// 奇数处理if(n % 2 !== 0){res[mid][mid] = count;}return res;};
加减计算器
class Calculate {constructor(value) {this.value = value;}add(value) {this.value += value;return this;}subtract(value) {this.value -= value;return this;}result() {return this.value}}const cal = new Calculate(50);console.log(cal.add(1).subtract(5).add(1000).subtract(5000).result());// 结果是-3954
富文本编辑器项目
https://codingartistweb.com/2022/04/rich-text-editor-with-javascript/
备注:今天下午去体测了 然后就去打球了,没有学习
