楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第三轮】6.16-6.22 CareerCup 1.7

🔗
asdw3276 2014-6-19 01:23:27 | 只看该作者
全局:
【解题思路】两次遍历,第一次记录flag,第二次根据flag设置矩阵
【时间复杂度】O(MN)
【空间复杂度】O(M+N)
【gist link】https://gist.github.com/asdw3276/fda81d69ab0bc1b0bb3b
回复

使用道具 举报

🔗
林微熙 2014-6-19 07:32:49 | 只看该作者
全局:
【解题思路】
two boolean arrays, one to tag the row which has 0s, and another to tag the column which has 0s. second pass is to set matrix[j] = 0 if row or column has zeros.
【时间复杂度】
O(M*N)
【空间复杂度】
O(M+N)
【gist link】https://gist.github.com/hilda8519/2d76dc3a2bb10751c167
回复

使用道具 举报

🔗
jyh橘子 2014-6-19 09:17:35 | 只看该作者
全局:
【解题思路】
use the first row and first column to record which row or column should be zero.   need some pre-process to record whether the first row or the first column have any zeroes.
【时间复杂度】
O(M*N)
【空间复杂度】
O(1)
【gist link】https://gist.github.com/jyhjuzi/af7a2e0a10787a06fb8b
回复

使用道具 举报

🔗
grassgigi 2014-6-21 10:32:25 | 只看该作者
全局:
【解题思路】
Keep two status sets tracking whether a row or column contains zero, and do in place replacement of zeros according to status sets.

【时间复杂度】
O(MN) for go through matrix twice
was stupidly trying to find some O(Max(M,N)) algo for an hour...
【空间复杂度】
O(M+N)

【gist link】
https://gist.github.com/chrislukkk/fd880801c2c56e28e2dc
回复

使用道具 举报

🔗
Tsien 2014-6-21 23:27:13 | 只看该作者
全局:
【解题思路】
a routine way:
use two sets to record where the element is zero,
then clear those rows and columns
【时间复杂度】
O(MN)
【空间复杂度】
O(M+N)
【gist link】
https://gist.github.com/Tsien/a39a2edf6c4535eba329
回复

使用道具 举报

🔗
七00夜 2014-6-21 23:53:19 | 只看该作者
全局:
【解题思路】
随机生成一个(0~9)的二维数组(M*N),并复制该数组,遍历原数组,找到0的下标i , j,并将新数组对应的i行和j列置0。
【时间复杂度】

【空间复杂度】

【gist link】
https://gist.github.com/ba245a6dd03dde387e60.git
回复

使用道具 举报

🔗
锦木千束 2014-6-22 00:41:24 | 只看该作者
全局:
【解题思路】两次遍历,第一次记录零所在的行列,第二次置零
【时间复杂度】O(MN)
【空间复杂度】O(M+N)
【gist link】https://gist.github.com/weazord/56924e3c39d5b898251



Test 1
Original:
1        0       
0        1       

Zeroes Set:
0        0       
0        0       

Test 2
Original
1        2        0        4        5       
6        7        8        9        10       
11        12        13        14        15       
16        17        18        19        20       

Zeroes Set:
0        0        0        0        0       
6        7        0        9        10       
11        12        0        14        15       
16        17        0        19        20       

Test 3
Original
1        2        3        4        5        6       
7        8        0        10        11        12       
13        14        15        16        0        18       
19        20        21        22        23        24       
25        26        27        28        29        30       

Zeroes Set:
1        2        0        4        0        6       
0        0        0        0        0        0       
0        0        0        0        0        0       
19        20        0        22        0        24       
25        26        0        28        0        30       



回复

使用道具 举报

🔗
bearkino 2014-6-22 06:04:15 | 只看该作者
全局:
【解题思路】
首先,先检查第一行和第一列,有0的话标记为true,然后检查matrix里面的元素,有0的话就在第一行或者第一列标记0. 然后set zero的时候,先检查第一行或者第一列是否有0,有的话就把对应的行列归零;然后检查是否有true, 有的话再把第一行或者第一列归零。结束。
【时间复杂度】
O(MN)
【空间复杂度】
O(1)
【gist link】
https://gist.github.com/UncleGarden/64c7132968c6c205605a
回复

使用道具 举报

🔗
bitcpf 2014-6-22 11:38:13 | 只看该作者
全局:

【解题思路】Traverse the matrix, find the zero row and column, then set the columns and rows' elements as 0
【时间复杂度】O(MN)
【空间复杂度】O(M+N)
【gist link】https://gist.github.com/bitcpf/91139d9c1a058eee5258

点评

等待你给我的code review~  发表于 2014-6-23 23:26
来自楼下的code review:求问空间复杂度是怎么算的? 以及,发现咱两程序不同的地方在于check该零是否原矩阵的时候,你相当于用了两个boolean[],我是用的两个boolean,但你的代码比我简洁和短  发表于 2014-6-23 23:26
回复

使用道具 举报

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

本版积分规则

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