cracking the coding interview No1.7
来源:互联网 发布:淘宝卖家账号出售 编辑:程序博客网 时间:2024/05/16 02:03
1.7 Write an algorithm such that if an element in an M*N matrix is 0,its entire row and column are set to 0;
Answer:
void function(int matrix[][],int m,int n){if (matrix == NULL)return;int i,j,k;int row[m],column[n];memset(row,1,sizeof(row));memset(column,1,sizeof(column));for (i = 0; i < m; i++){for (j = 0; j < n; j++){if (matrix[i][j] == 0){row[i] = 0;column[j] = 0;}}}for (i = 0; i < m; i++){for (j = 0; j < n; j++){if (row[i] == 0 || column[j] == 0){matrix[i][j] = 0;}}}}
0 0
- cracking the coding interview No1.7
- cracking the coding interview No1.1
- cracking the coding interview No1.2
- cracking the coding interview No1.3
- cracking the coding interview No1.4
- cracking the coding interview No1.5
- cracking the coding interview No1.6
- cracking the coding interview No1.8
- Cracking the Coding Interview
- 《Cracking the coding interview》
- Cracking The Coding Interview
- Cracking the coding interview
- Cracking the coding interview
- Cracking the coding interview--Q9.7
- Cracking the coding interview--Q1.7
- Cracking the coding interview--Q1.7
- Cracking the coding interview--Q4.7
- Cracking the coding interview--Q5.7
- Cocos2d-x_CCMenu(菜单类)介绍
- 应用分发新三国时代:生态的终极PK
- javascript中的typeof
- 第八周 项目8 税收问题 (if else 语句)
- 总在灵魂深处,藏了一些喜悲
- cracking the coding interview No1.7
- Audio笔记之MixerThread
- 第八周项目 4 个人所得税计算机
- yaml格式小问题
- hdu 5012 Dice 2014 ACM/ICPC Asia Regional Xi'an Online
- 作价超40亿,苏宁缺钱卖店还是另辟新径?
- Linux实验二【最简单kernel module的例子】
- zoj 3195 Design the city(LCA)
- C++浮点数比较