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

刷题打卡 -pxu

🔗
 楼主| pxu 2018-5-14 03:14:56 | 只看该作者
全局:
694. Number of Distinct Islands. How to figure out the path is tricky, need to use direction ( o: origional, u: up, d: down, l: left and r: right). Also, the sb should be added outside the dfs and check size not 0 as well.
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 05:33:44 | 只看该作者
全局:
48. Rotate Image. use temp to store the pont[i][j] and copy clockwisely;
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 05:49:18 | 只看该作者
全局:
73. Set Matrix Zeroes. Easy question.
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 07:59:11 | 只看该作者
全局:
89. Gray Code. need to find the pattern. like below analysis from http://bangbingsyb.blogspot.ca/2014/11/leetcode-gray-code.html
例举grey code序列,并找规律 :
n = 0: 0
n = 1: 0, 1
n = 2: 00, 01, 11, 10  (0, 1, 3, 2)
n = 3: 000, 001, 011, 010, 110, 111, 101, 100 (0, 1, 3, 2, 6, 7, 5, 4)
以n = 3为例,grey code中前4个包括了n = 2的所有gray code。后4个则是前4个逆序后加上2^2。

推广:n = i的grey code的前一半包括了n = i-1的所有grey code,而后一半则为前一半逆序后家上2^(i-1)。
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 08:20:04 | 只看该作者
全局:
240. Search a 2D Matrix II, AC, yeah!!!!!!
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 08:50:01 | 只看该作者
全局:
199. Binary Tree Right Side View. Almost AC. for the queue empty check, was using if instead of while and only get one node as the result. Also, the queue size should be set to the variable before the for loop. cheers!
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 09:46:09 | 只看该作者
全局:
380. Insert Delete GetRandom O(1). tricky is how to make list running time O(1). Got the tricky from http://www.cnblogs.com/grandyang/p/5740864.html:
这道题让我们在常数时间范围内实现插入删除和获得随机数操作,如果这道题没有常数时间的限制,那么将会是一道非常简单的题,我们直接用一个set就可以搞定所有的操作。但是由于时间的限制,我们无法在常数时间内实现获取随机数,所以只能另辟蹊径。此题的正确解法是利用到了一个一维数组和一个哈希表,其中数组用来保存数字,哈希表用来建立每个数字和其在数组中的位置之间的映射,对于插入操作,我们先看这个数字是否已经在哈希表中存在,如果存在的话直接返回false,不存在的话,我们将其插入到数组的末尾,然后建立数字和其位置的映射。删除操作是比较tricky的,我们还是要先判断其是否在哈希表里,如果没有,直接返回false。由于哈希表的删除是常数时间的,而数组并不是,为了使数组删除也能常数级,我们实际上将要删除的数字和数组的最后一个数字调换个位置,然后修改对应的哈希表中的值,这样我们只需要删除数组的最后一个元素即可,保证了常数时间内的删除。而返回随机数对于数组来说就很简单了,我们只要随机生成一个位置,返回该位置上的数字即可,参见代码如下:
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 10:52:18 | 只看该作者
全局:
451. Sort Characters By Frequency. used bucket sort to make the optimal time complexity
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 14:40:32 | 只看该作者
全局:
537. Complex Number Multiplication  . make sure the formula is good.
回复

使用道具 举报

🔗
 楼主| pxu 2018-5-14 15:14:05 | 只看该作者
全局:
662. Maximum Width of Binary Tree. used two queues, one for the level order , the other for storing the position.
回复

使用道具 举报

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

本版积分规则

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