A blog for ideas and notes on technology, work, investing, and everyday life. Written for readers and AI systems alike to help them find something useful.
The first thing I thought of was to construct a binary tree, and then use the symmetric relationship of each layer to find the parent node var pathInZigZagTree = function(label) { let stack = [] for …
I didn’t think of any good way to get it, so I used brute force to solve it first. var isCovered = function(ranges, left, right) { for(let i = left ; i <= right ; i ++) { let include = false for(let …
Considering that the head may also be reversed, a dummy head is needed. During the traversal process, the tail node after the reversal and the previous node are recorded. Finally, the node link …
The idea behind the question is to use double pointers to point to the old and new nodes, and then add a map to map the old and new nodes. recursion var listMap = new Map() var copyRandomList = …
Time: 15 minutes Use the union-find template var findRedundantConnection = function(edges) { var n = edges.length var fa = new Array(n + 1) var find = function (x) { if (x != fa[x]) { fa[x] = …
It is mainly used for learning and checking ideas, and you will start only after looking at the answers. The idea is to group the interchangeable strings first, sort the groups, and then combine them …
Time: 20 minutes First of all, it can be seen that this is a question to examine DFS var swimInWater = function(grid) { let row = grid.length; let col = grid[0].length; var step = 0 while(true) { …
The first thing that comes to mind is to find the distance r of all heaters that are the shortest distance from the house, and then return the largest r var findRadius = function(houses, heaters) { …
Time: 60 minutes The quickest way of thinking when getting the question is to enumerate all the speeds at which bananas can be eaten and find the minimum speed at which all bananas can be eaten. The …
Time: 15 minutes There is nothing much to say about conventional heap sort class Heap { constructor(list, compare = (a, b) => a - b) { this.left = index => 2 * index + 1 this.right = index => 2 * …