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)... 阅读全文
posted @ 2014-07-18 02:09 门对夕阳 阅读(195) 评论(0) 推荐(0)
摘要:Problem: Implement a function to check if a singly linked list is a palindrome.思路:最简单的方法是 Reverse and compare.另外一种非常经典的办法是用 Recursive 的思路,把一个list看成这种形... 阅读全文
posted @ 2014-07-16 00:02 门对夕阳 阅读(429) 评论(0) 推荐(0)
摘要:去Twitter面试的被问到这个问题,当时只想到了用HashMap的办法,这种办法时间复杂度O(n),空间复杂度是O(n), 更好的办法是用 FastRunner / SlowRunner approach。用两个pointer遍历链表,fast的速度是slow的两倍,如果有loop,二者一定会co... 阅读全文
posted @ 2014-07-15 05:45 门对夕阳 阅读(297) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2014-07-15 01:53 门对夕阳 阅读(168) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2014-07-10 02:24 门对夕阳 阅读(329) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2014-07-09 09:31 门对夕阳 阅读(252) 评论(0) 推荐(0)

点击右上角即可分享
微信分享提示