07 2014 档案
摘要:堆有两种: 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...
阅读全文