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

刷题打卡 -pxu

🔗
 楼主| pxu 2018-6-9 05:54:59 | 只看该作者
全局:
763. Partition Labels
make sure max(max, hash[i]) to get the updated end;
check current i == end
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-9 06:31:30 | 只看该作者
全局:
762. Prime Number of Set Bits in Binary Representation
try to get the count of 1s in the binary;
1 is not prime and 2 is the primary, make sure handle that in the isPrime method
for(int i = 2; i*i <= num;i++){
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-9 09:18:11 | 只看该作者
全局:
535. Encode and Decode TinyURL
used hashmap and Random class
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-9 11:01:55 | 只看该作者
全局:
380. Insert Delete GetRandom O(1)
public boolean remove(int val) {
        // write your code here
        if(!posMap.containsKey(val)){
            return false;
        }
        
        Integer lastVal = list.get(list.size()-1);
        int posLast = posMap.get(lastVal);
        int posOfVal = posMap.get(val);
        
        if(posLast != posOfVal){
            posMap.put(lastVal, posOfVal);
            list.set(posOfVal,lastVal);
        }
        
        list.remove(list.size()-1);
        posMap.remove(val);
        return true;
        
    }
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-9 12:08:56 | 只看该作者
全局:
74. Search a 2D Matrix - AC,easy
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-10 10:24:07 | 只看该作者
全局:
235. Lowest Common Ancestor of a Binary Search Tree
make sure return when root = p or q

236. Lowest Common Ancestor of a Binary Tree
TreeNode left = lowestCommonAncestor(root.left, p, q);
TreeNode right = lowestCommonAncestor(root.right, p, q);

if(left != null && right != null){
    return root;
}
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-10 11:04:19 | 只看该作者
全局:
234. Palindrome Linked List.txt
the stack should push data < len/2; skip value check on len/2 and odd len
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-10 16:17:29 | 只看该作者
全局:
92. Reverse Linked List II
find preM, mNode and nNode postion and keep on move mNode after nNode, and point mNode to preM.next, util mNode == nNode
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-10 16:46:37 | 只看该作者
全局:
204. Count Primes
isPrime[]
其算法是,给出要筛数值的范围, 找出以内的素数. 先用2去筛,即把2留下,把2的倍数剔除掉;再用下一个素数,也就是3筛,把3留下,把3的倍数剔除掉;接下去用下一个素数5筛,把5留下,把5的倍数剔除掉;不断重复下去。
回复

使用道具 举报

🔗
 楼主| pxu 2018-6-11 06:49:18 | 只看该作者
全局:
119. Pascal's Triangle II.txt
append 1 on every look, update value from right to left;

for(int i = 0; i <= rowIndex; i++){
            res.add(1);
            
            for(int j = i - 1; j > 0; j--){
                res.set(j, res.get(j-1) + res.get(j));
            }
        }
回复

使用道具 举报

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

本版积分规则

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