1.8 Zero Matrix
来源:互联网 发布:linux codeblocks教程 编辑:程序博客网 时间:2024/05/24 05:27
Using the first row and column to store that row and col’s state:
if there is a ‘0’ element matrix[i][0] = matrix[0][j] = 0.
And using a tmp variable (at here it’s called col0) to indicate the first element of each row, if it’s 0 then tmp = 0 or tmp = 1;
Finally, we set the matrix bottom up.
void setZeroes(vector<vector<int>>& matrix){ int m = matrix.size(), n = matrix[0].size(); int col0 = 1; for (int i = 0; i<m; ++i) { if (matrix[i][0] == 0) col0 = 0; for (int j = 0; j<n; ++j) { if (!matrix[i][j]){ matrix[i][0] = 0; matrix[0][j] = 0; } } } for (int i = m-1; i >= 0; --i) { for (int j = n - 1; j >= 1; --j) { if (!matrix[i][0] || !matrix[0][j]) matrix[i][j] = 0; } if (!col0) matrix[i][0] = 0; } }
0 0
- 1.8 Zero Matrix
- [leetcode]set matrix zero
- leetcode-set Matrix Zero
- leetcode Set Matrix Zero
- set matrix zero
- CC150 Arrays and Strings 1.7 ~ 1.8 Set Matrix Zero, IsS1RotationOfS2
- Count zero segments in matrix
- zero
- zero
- Zero+
- zero
- ZERO
- Looping over the non-zero elements of a uBlas sparse matrix
- 1.8 Rotate Matrix
- 《Matrix》
- Matrix
- Matrix
- Matrix
- [Servlet]HttpServletRequest的请求参数、标头、编码
- J2SE基础
- Android 绘制虚线
- SLAM: 单目视觉SLAM的方案分类
- 收藏夹
- 1.8 Zero Matrix
- 聊聊Android中的WebView控件
- MyBatis入门学习教程
- 诺亚方舟实验室李航:深度学习还局限在复杂的模式识别上
- 1031. Hello World for U
- 建立驱动sysfs接口
- C 缓冲区
- Log日志规范(转)
- memcached-session-manager 配置问题