摘要: Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.如果不用额外空间的话,可以把第一行与第一列作为标记行与标记列,但是得先确定第一行与第一列本身要不要设为0。 1 class Solution { 2 public: 3 void setZeroes(vector > &matrix) { 4 if (matrix.size() < 1) return; 5 int row = matrix.size(), col = matri... 阅读全文
posted @ 2014-04-05 13:54 Eason Liu 阅读(212) 评论(0) 推荐(0) 编辑
摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.最开始的想法就是暴力复制,时间复杂度为O(n^2),写的时候就感觉要出现事,果不其然,超时了,后来网上看到一个O(n)的算法,非常巧妙的利用了原来链表的信息:该算法更为巧妙,不用保存原始链表的映射关系,构建新节点时,指针做如下变化,即把新节点插入到相应的旧节点后面:同理分两步 阅读全文
posted @ 2014-04-05 13:34 Eason Liu 阅读(4297) 评论(3) 推荐(0) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t... 阅读全文
posted @ 2014-04-05 01:11 Eason Liu 阅读(1359) 评论(0) 推荐(0) 编辑
摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", &q 阅读全文
posted @ 2014-04-05 00:33 Eason Liu 阅读(214) 评论(0) 推荐(0) 编辑