leetcode — set-matrix-zeroes】的更多相关文章

Set Matrix ZeroesGiven 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 simple im…
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 simple improvement uses O…
原题地址:https://oj.leetcode.com/problems/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. 解题思路:分别记录两个向量x, y,保存行和列是否有0,再次遍历数组时查询对应的行和列然后修改值. 代码: class Solution: # @param matrix, a list of…
http://oj.leetcode.com/problems/set-matrix-zeroes/ 因为空间要求原地,所以一些信息就得原地存储.使用第一行第一列来存本行本列中是否有0.另外对于第一个元素[0][0],需要额外处理. #include <iostream> #include <vector> using namespace std; class Solution { public: void setZeroes(vector<vector<int>…
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 原题链接:https://oj.leetcode.com/problems/set-matrix-zeroes/ 题目:给定一个m * n 的矩阵.假设有一个元素是0.将其所在行和列设为0. 思路:先记录下是0 的元素的位置.再去置0. public void setZeroes(int[][] matrix)…
题意: 给一个n*m的矩阵,如果某个格子中的数字为0,则将其所在行和列全部置为0.(注:新置的0不必操作) 思路: 主要的问题是怎样区分哪些是新来的0? 方法(1):将矩阵复制多一个,根据副本来操作原矩阵. 方法(2):发现空间还可以用O(n)来解决. 方法(3):若m[i][j]=0,则将m[i][0]和m[0][j]标记为0,表示i行和j列都为0,但是这样的问题是,首行和首列会冲突?那就将首列先预处理一下,用另外的常量标记就行了.时间复杂度O(n*m),空间O(1). class Solut…
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(m n) space is probably a bad idea.A simple improvement uses…
1. Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. Example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 思路:这题感觉有点没有说清楚,如果k大于了链表长度该怎么办呢?这个时候怎么确定旋转位置呢?从右往左数,超出数组…
Set Matrix Zeroes Total Accepted: 18139 Total Submissions: 58671My Submissions 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. 题意:给定矩阵,假设矩阵的某个位置为0.则把那一行那一列的全部元素都置为0 思路:用两个bool数组,分…
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 simple…