// * a1, array // * a2, array var intersect = function(a1, a2) { // * store result // * can be duplicated const res = []; // ns1 = a1, ns2 = a2; or the other way around let ns1, ns2; // * ns1 is always small; ns2 is alway large // * ns1.len == ns2.len, ...
// Solution 2: This is a clever solution. (I'm not saying it's a short solution.) Took me more than an hour to figure out. First of all, I believed there's a better solution to this problem than an O(N ^ 2) brute-force one. Because it's about "order", and you know there...
Welcome to "LeetCode The Hard Way," the ultimate resource for those looking to improve their skills in data structures and algorithms! Our website is dedicated to providing comprehensive tutorials and detailed solutions to some of the most challenging problems in LeetCode. Whether you're a studen...
// because we know the height is strictly increasing, we can calculate the width // since index.top() store the index which points to the height lower than current // the width is i - index.top() - 1 // if its the last item to be poped, its the smallest, thus width is i in...
In this problem, the task is to find two numbers in the array 'nums' that add up to the given 'target' and return their indices. In the given example, the numbers at indices 0 and 1 (2 and 7) add up to the target value of 9, so the function should return [0, 1]. LeetCode...
115.It's truely a good problem. Though the difficulty is hard, you can easily do it when you understand what is dynamic programming. The first of discussion have a good explanation, and maybe you should explan this problem like that. ...
460 LFU Cache 28.6% Hard Partition Equal Subset Sum 【题目】Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. Note: Each of the array element will not exceed 100...
409 Longest Palindrome Python Java Length of Palindrome is always 2n or 2n + 1. So, get all possible 2*n, and choose a single one as 1 if it exists. 412 Fizz Buzz Python Java 1. From 1 to n, condition check2. Condition check and string connect 414 Third Maximum Number Python Java...
Course Schedule, Longest Increasing Path in a Matrix and Alien Dictionary. Note that some of the tree problems can also be asked in n-ary tree format, so make sure you know what an n-ary tree is. Note: The last problem may be quite tricky to solve, so feel free to skip that one....
Is it just me? 我tmd自从来美国,交了不知多少罚款了,每次都是掏钱息事宁人,然后难受一晚上第二天就忘光了。Also, I’m bad at negotiation,一要跟人argue我就浑身难受,usually just choose to settle just to make ppl like me. Will it ever change? If so, what can I do to change?