# Daily Archives: April 12, 2015

## [leetcode] Remove Duplicates from Sorted Array II

Remove Duplicates from Sorted Array II Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice? For example, Given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3]. 很奇怪的题，和此题的第一代没有本质区别。 只要增加一个变量count记录当前已经出现的相同数字的个数。 如果count>2，不移动start，如果小于等于2，copy A[i] to A[start++]。 class Solution { public: int […]

## [leetcode] Search a 2D Matrix

Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous […]

## [leetcode] Set Matrix Zeroes

Set Matrix Zeroes Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up:Did you use extra space? A straight forward solution using O(mn) space is probably a bad idea. A […]