摘要: Q:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still not the best solution.Could you devise a constant space 阅读全文
posted @ 2013-09-16 23:01 summer_zhou 阅读(337) 评论(0) 推荐(0) 编辑
摘要: Q:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it c 阅读全文
posted @ 2013-09-16 15:01 summer_zhou 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Q:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2->4-> 阅读全文
posted @ 2013-09-16 10:57 summer_zhou 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Q:Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].A: 先按interval的start排序,后顺序扫描进行merge vector merge(vector &intervals) { // Start typing your C/C++ solution below // DO NOT write int main() functio... 阅读全文
posted @ 2013-09-16 10:07 summer_zhou 阅读(140) 评论(0) 推荐(0) 编辑