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

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

🔗
jing0328 2014-6-18 22:50:24 | 只看该作者
全局:
【解题思路】assume rotate the matrix counterclockwise by 90 degree, do this by first taking the transpose and then flip the matrix horizontally
【时间复杂度】O(n^2)
【空间复杂度】O(n)
【gist link】https://gist.github.com/startupjing/a00d007735cb93527de4
回复

使用道具 举报

🔗
asdw3276 2014-6-19 01:57:07 | 只看该作者
全局:
【解题思路】 leetcode原题,通过观察我们可以发现旋转是4个一组进行旋转,所以只需要循环1/4个矩阵就可以了,每次把4个元素顺时针置换一下。
【时间复杂度】O(n^2)
【空间复杂度】O(1)
【gist link】https://gist.github.com/asdw3276/a4f9223bb5f678e50cbb
感谢给我code review的小伙伴~
回复

使用道具 举报

🔗
林微熙 2014-6-19 06:56:45 | 只看该作者
全局:
【解题思路】
same to the one on book
【时间复杂度】
O(N^2)
【空间复杂度】
O(1)
【gist link】https://gist.github.com/hilda8519/ed4f00a6b57be514e9a6
回复

使用道具 举报

🔗
jyh橘子 2014-6-19 08:34:31 | 只看该作者
全局:
【解题思路】
implement layer by layer
【时间复杂度】
O(N^2)
【空间复杂度】
O(1)
【gist link】 https://gist.github.com/jyhjuzi/0fb0c4ae211667a73cc9
回复

使用道具 举报

🔗
pud 2014-6-21 06:18:45 | 只看该作者
全局:
【解题思路】
和书上一样,一层一层循环
【时间复杂度】
O(N^2)
【空间复杂度】
O(1)
【gist link】 https://gist.github.com/yokiy/082210d39d5254f540f6
回复

使用道具 举报

🔗
grassgigi 2014-6-21 08:48:59 | 只看该作者
全局:
【解题思路】
Rotating from outer layer to inner layer, like peeling the onion.

【时间复杂度】
O(N^2) since all element(N^2) in martrix will be moved.

【空间复杂度】
O(1)

【gist link】
https://gist.github.com/chrislukkk/2722328bce613265cf19

【test case】
create random-generated matrix for test, print out for verification
回复

使用道具 举报

🔗
锦木千束 2014-6-21 21:47:32 | 只看该作者
全局:
本帖最后由 锦木千束 于 2014-6-21 21:48 编辑

【解题思路】没思路。。把旋转过程写在记事本上找规律 Orz。。。。 笨死了
【时间复杂度】O(N^2)
【空间复杂度】O(1)
【gist link】https://gist.github.com/weazord/2d632a5aa056cd0ae7b5

Test 1
Original:
1        2        3        4        5        
6        7        8        9        10        
11        12        13        14        15        
16        17        18        19        20        
21        22        23        24        25        

Rotated:
21        16        11        6        1        
22        17        12        7        2        
23        18        13        8        3        
24        19        14        9        4        
25        20        15        10        5        

Test 2
Original
1        2        3        4        5        6        
7        8        9        10        11        12        
13        14        15        16        17        18        
19        20        21        22        23        24        
25        26        27        28        29        30        
31        32        33        34        35        36        

Rotated:
31        25        19        13        7        1        
32        26        20        14        8        2        
33        27        21        15        9        3        
34        28        22        16        10        4        
35        29        23        17        11        5        
36        30        24        18        12        6        

Test 3
Original
1        

Rotated:
1        


回复

使用道具 举报

🔗
Tsien 2014-6-21 23:10:22 | 只看该作者
全局:

【解题思路】
// [i, j] --> [j, N - i - 1]

【时间复杂度】
O(N^2)

【空间复杂度】
O(1)

【gist link】
https://gist.github.com/Tsien/a39a2edf6c4535eba329
回复

使用道具 举报

🔗
bitcpf 2014-6-22 01:09:24 | 只看该作者
全局:
【解题思路】Assume the rotate is clockwise, then for each layer, implement left to top, bottom to left, right to bottom and top to right
【时间复杂度】O(N^2) all emements need to be moved
【空间复杂度】O(1)
【gist link】https://gist.github.com/bitcpf/99fafb2eca0cce561a09
回复

使用道具 举报

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

本版积分规则

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