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

[CareerCup] [第二轮] 2/18-2/24 CareerCup 1.7

🔗
zuohr 2013-2-18 10:33:18 | 只看该作者
全局:
本帖最后由 zuohr 于 2013-2-18 10:40 编辑
ryancooper 发表于 2013-2-18 07:26
Your idea is nice, but you do a lot of redundant works. In your code, you unnecessarily record too ...


I come up with an idea which is similar to your solution but require only one extra arry to record column information, which is as below:
Traverse through the matrix and keep a boolean flag to mark if there is any element equal to zero in this row, and record column information as you did. Here is the trick, when we switch the row, ie. move from one row to the next, we immediatly set the last row to zero if the flag is true because we do not have to keep the last row any more. Then we only need one boolean variable to keep row information instead of an array. There is no difference in terms of run-time performance, but we have less space overhead.
回复

使用道具 举报

🔗
czhoume 2013-2-18 12:11:14 | 只看该作者
全局:
Here is my solution: https://gist.github.com/czhoume/4975058

mark col number and row number that we need to set to zero in 2 boolean array and traverse the 2 array and set the corresponding col and row to 0.
回复

使用道具 举报

🔗
ryancooper 2013-2-18 13:17:39 | 只看该作者
全局:
zuohr 发表于 2013-2-18 10:33
I come up with an idea which is similar to your solution but require only one extra arry to reco ...

Yeah, we can do that. Your improvement is good
回复

使用道具 举报

🔗
liuzhe1218 2013-2-20 13:57:51 | 只看该作者
全局:
I don't understand the meaning of it? Can it be explained in this way: if one of the elements in this matrix is 0, the whole matrix is 0?
回复

使用道具 举报

全局:
Use a boolean matrix to record zeros and then set zeros.
I think I use too many loops.

https://gist.github.com/lynntian/5001309
回复

使用道具 举报

🔗
liuzhe1218 2013-2-21 18:37:43 | 只看该作者
全局:
Java language
https://gist.github.com/mettaworld/5003802
make two functions which store the locations of zero from origin matrix  and make the affected row and column into zero
回复

使用道具 举报

🔗
youling_tong 2013-2-22 09:52:16 | 只看该作者
回复

使用道具 举报

🔗
moophis 2013-2-22 14:13:45 | 只看该作者
全局:
https://github.com/moophis/careercup/blob/master/1.7.cpp
1. Scan through all elements and flag those with value 0;
2. Set the value of rows and columns with 0 value element 0.
回复

使用道具 举报

🔗
lazyGoose 2013-2-23 06:38:55 | 只看该作者
全局:
put the (x, y) of a Zero Position into A temp array.
Zero the row and colume one by  one


https://gist.github.com/lazyGoose/5017107
回复

使用道具 举报

🔗
Kimurate 2013-2-23 12:00:17 | 只看该作者
全局:
* Method: Hold flags of row and col in two one-dimension arrays,
* set the related elements later.
C language: https://gist.github.com/hukun01/5018306
回复

使用道具 举报

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

本版积分规则

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