查看: 4311| 回复: 115
跳转到指定楼层
上一主题 下一主题
收起左侧

每日打卡

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
楼主30号fb一面,20号google oa,另有ipsy的ml intern.
用本帖来记录并鼓励自己,同时记录心得

评分

参与人数 1大米 +5 收起 理由
fjn19971007 + 5 给你点个赞!

查看全部评分


上一篇:该用java还是javascript刷题?web developer背景
下一篇:uwi 为什么长期霸占lc contest 第一位置
推荐
 楼主| chenxianggre 2018-11-20 08:09:24 | 只看该作者
全局:
38. Count and Say
不断存入字符,使用递归。
class Solution {
public:
    string countAndSay(int n) {
        
        
        return find("1",n);
    }
   
    string find(string str, int n){
        if(n==1)return str;
        n--;
        int count=1;
        string res="";
        for(int i=0;i<str.size()-1;i++){
            if(str[i]==str[i+1])count++;
            else {res+=count+'0';res+=str[i];count=1;}
        }
        res+=count+'0';res+=str[str.size()-1];
        return find(res,n-1);
    }
};
回复

使用道具 举报

推荐
 楼主| chenxianggre 2018-11-20 08:21:37 | 只看该作者
全局:
398. Random Pick Index
使用rand()%cnt;非常精彩的地方!!
class Solution {
public:
    Solution(vector<int> nums): v(nums) {}
   
    int pick(int target) {
        int cnt = 0, res = -1;
        for (int i = 0; i < v.size(); ++i) {
            if (v[i] != target) continue;
            ++cnt;
            if (rand() % cnt == 0) res = i;
        }
        return res;
    }
private:
    vector<int> v;
};
回复

使用道具 举报

推荐
 楼主| chenxianggre 2018-11-20 11:59:39 | 只看该作者
全局:
377. Combination Sum IV

回看 使用dp
class Solution {
public:
    int combinationSum4(vector<int>& nums, int target) {
        vector<int> dp(target + 1);
        dp[0] = 1;
        for (int i = 1; i <= target; ++i) {
            for (auto a : nums) {
                if (i >= a) dp[i] += dp[i - a];
            }
        }
        return dp.back();
    }
};
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 08:34:34 | 只看该作者
全局:
上午十点才起,磨蹭到下午开个会,现在四点了,今天希望能快速过一遍leetcode fb tag题目
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 08:48:55 | 只看该作者
全局:
314 Binary Tree Vertical Order Traversal :
难点在于如何初始化数组序列,无法轻易向前加元素:使用map<int,vector<int>>m 从而避免下标从0开始的问题,之后用auto a:m a.second 来组成返回vector;
可是为什么要用quene?没发现必要性,待解决。


补充内容 (2018-11-25 06:50):
queue has the attribute of first in first out, therefore it could be use as loop

补充内容 (2018-11-25 08:09):
void bfs(queue<pair<int,TreeNode*>>& q,map<int,vector<int>>& m){
        if(q.empty())return;
        int n=q.size();
        for(int i=0;i<n;i++){
            auto a=q.front();
            q.pop(...
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 08:49:20 | 只看该作者
全局:
另外 找组织 找队友一起刷题
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 08:57:31 | 只看该作者
全局:
abandon 10 regular expression match
这道题很难,准确说有很多细节需要讨论:
时间本来不多 我何必折磨自己
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 09:33:50 | 只看该作者
全局:
301 此题需要了解矩阵的乘法,然后如果相乘的元素之一为0,跳转下一次,复杂度虽然相同,但是省掉很多步骤
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 09:49:18 | 只看该作者
全局:
543:Diameter of Binary Tree
遍历所有子节点和root节点,找出左深度和右深度和最大的值
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 09:55:17 | 只看该作者
全局:
278 first bad version
使用二分法找到a[i]bad but a[i-1]不是bad。
简单题真是快啊
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 12:13:19 | 只看该作者
全局:
277 find the celebrity
用最简单的遍历方法
回复

使用道具 举报

🔗
 楼主| chenxianggre 2018-11-17 12:20:09 | 只看该作者
全局:
680 valid palindrome
双向遍历,如何不对,各自删除,继续遍历,如果正确,返回true,否则false
回复

使用道具 举报

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

本版积分规则

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