12
返回列表 发新帖
楼主: pure0909
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第四轮】3.30 -4.5 Career Cup 1.7

🔗
slaink 2015-4-5 06:15:36 | 只看该作者
全局:
本帖最后由 slaink 于 2015-4-5 06:18 编辑

解题思路】
// If martix[j] = 0, then martix[i][] = 0 and matrix[][j] = 0        
// We construct two array indicators to log if a row/col should be set to zero
[/i][i]【时间复杂度】
* Time complexity: O(m*n)
【空间复杂度】
* Space complexity: O(m+n)
【gist link] https://github.com/bxshi/intervi ... I5/1_7_set_zero.cpp
【test case】(optional,如果觉得比较好,欢迎贴出来分享) https://github.com/bxshi/intervi ... c/test/1_7_test.cpp
[/i]

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
daphne_ying 2015-4-6 04:21:37 | 只看该作者
全局:
[solution]
1. use two bool arrays, one to indicate whether a row should be set to zero, another to indicate whether a col should be set to zero.
2. first scan of the matrix to update the two bool arrays.
3. second scan of the matrix to set the correspond elements.
[time]
O(mn)
[space]
O(m+n)
[gist]
https://gist.github.com/kelly-us/9d0af336171822f9c17e

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

全局:
【解题思路】
* First, we at least need two loops, one for finding out the rows and columns containing 0,
* the other one to set 0. We cannot do it in one loop, because it will influence result.
* We set the row and column which contain 0, true.
* Then in the next loop, if row or column is true, we set it 0.
*
* Note: "or" is very important here, think about it. I used three loops initially, which is not most efficient.
【时间复杂度】
O(MN)
【空间复杂度】
O(M+N)
【gist link】
https://gist.github.com/leonw007/47cf3244fea404e21562
【test case】included in the link above

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
sevenwonder 2015-4-6 11:06:49 | 只看该作者
全局:
【解题思路】
可以开一个行数组row和列数组col,当元素a[i][j]等于0时, 就把row[i]和col[j]置为true。第二次遍历矩阵时,当某个元素对应的行row[i] 或列col[j]被设置为true,说明该元素在需要被置0的行或列上,因此将它置0。
【时间复杂度】
O(MN)
【空间复杂度】
O(M+N)
【gist link】
https://gist.github.com/songpu2015617/46b8ba53f41adb40560a

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
Godbless 2015-4-6 13:25:58 | 只看该作者
全局:
【解题思路】Two passes: First pass to find the row indexes and column indexes which contain 0 element. Second pass to set the element which lies either in the row indexes or column indexes to zero.
【时间复杂度】O(MN)
【空间复杂度】O(M+N)
【gist link]
https://github.com/StephenWeiXu/ ... blob/master/1_7.cpp
【test case】(optional,如果觉得比较好,欢迎贴出来分享)
https://github.com/StephenWeiXu/ ... blob/master/1_7.cpp

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
beer 2015-4-7 01:45:17 | 只看该作者
全局:
【解题思路】
Tips:
* Use two array to mark which row and which col should be reset to zero perspectively.
* Use the first row and column to mark which row and col should be reset to zero perspectively.
【时间复杂度】1&2. O(M*N)
【空间复杂度】1. O(M+N) 2.O(1)
【gist link】https://github.com/drinkbeer/Cod ... /src/CC150_1_7.java
【test case】

评分

参与人数 1大米 +7 收起 理由
pure0909 + 7 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
yaooffer 2015-9-13 06:04:21 | 只看该作者
全局:
【gist link】github.com/Etherque/Career-Cup/blob/master/setZeros.java"
Time Complexity O(m x n)
Space O(1)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表