摘要:
阅读全文
摘要:
堆有两种: max-heap 和 min-heap. Max-heap 一般用来排序,Min-heap 用来实现 priority queue.max-heap的定义是:for each i: A[parent(i)] >= A[i]min-heap: for each i: A[parent(i)... 阅读全文
摘要:
Problem: Implement a function to check if a singly linked list is a palindrome.思路:最简单的方法是 Reverse and compare.另外一种非常经典的办法是用 Recursive 的思路,把一个list看成这种形... 阅读全文
摘要:
去Twitter面试的被问到这个问题,当时只想到了用HashMap的办法,这种办法时间复杂度O(n),空间复杂度是O(n), 更好的办法是用 FastRunner / SlowRunner approach。用两个pointer遍历链表,fast的速度是slow的两倍,如果有loop,二者一定会co... 阅读全文
摘要:
Partition an array of integers around a value such taht all elements less than x come before elements greater than or equal to x.Idea: Just use of sub... 阅读全文
摘要:
We all know how to search through an array for an element whose value equals the target value, but how to search for the element that has value greate... 阅读全文
摘要:
Given a sorted array that has been rotated serveral times. Write code to find an element in this array. You may assume that the array was originally s... 阅读全文
摘要:
where vs having当一个sql语句中存在where子句,会先执行where,然后执行group by,然后执行having.一般来说,only use 'having' when you use 'group by'Always use 'having' with aggregate f... 阅读全文
摘要:
Given a list of millions of documents, how would you find all documents that contain a list of words? The words do not need to appear in any particula... 阅读全文
摘要:
给一堆盒子,知道每个盒子的三围(长宽高),盒子正面朝你,不能旋转摆放,按照大的放在小的下面的原则堆起来,必须是 strictly larger,同样大小的盒子不行,问怎么样堆到最大的高度?思路:动态规划最优解一定是 max( {box_1 be the bottom}, {box_2 be the ... 阅读全文