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

在职刷题打卡

🔗
 楼主| 中心点 2019-4-20 07:15:46 | 只看该作者
全局:
本帖最后由 中心点 于 2019-4-20 14:04 编辑

4/19
1. Continuous Subarray Sum;
2. Subarray Sum Equals K
3. Expression Add Operators
4. Remove Invalid Parentheses
5. Add Binary

回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-21 13:30:14 | 只看该作者
全局:
4/20
Add and Search Word - Data structure design
回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-21 13:42:40 | 只看该作者
全局:
本帖最后由 中心点 于 2019-6-16 14:55 编辑

就刷了一题
回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-21 13:44:58 | 只看该作者
全局:
Add and Search Word - Data structure design。 这个trie的解法竟然只比5%的submissions快,难道可以再优化时间吗?

struct Node{
    bool isWord;
    unordered_map<char, Node*> children;
    Node(){
        isWord = false;
    }
};
class WordDictionary {
public:
    /** Initialize your data structure here. */
    WordDictionary() {
        root = new Node();
    }
   
    /** Adds a word into the data structure. */
    void addWord(string word) {
        Node* dummy = root;
        for(char c: word){
            if(!dummy->children[c])
                dummy->children[c] = new Node();
            dummy = dummy->children[c];
        }
        dummy->isWord = true;
    }
   
    /** Returns if the word is in the data structure. A word could contain the dot character '.' to represent any one letter. */
    bool search(string word) {
        Node* dummy = root;
        return help(word, 0, dummy);
    }
   
    bool help(string &word, int id, Node* root){
        if(!root)
            return false;
        if(id == word.size())
            return root->isWord;
        unordered_map<char, Node*> cur_children = root->children;
        char c = word[id];
        if(c != '.')
            return help(word, id + 1, cur_children[c]);
        for(auto it = cur_children.begin(); it != cur_children.end(); it++){
            if(help(word, id + 1, it->second))
                return true;
        }
        return false;
    }
private:
    Node* root;
};
回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-22 11:26:48 | 只看该作者
全局:
本帖最后由 中心点 于 2019-4-26 14:01 编辑

4/21
  • Search in Rotated Sorted Array:  compare A[mid] vs target; then A[mid] vs A[left]
  • Valid Parentheses


回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-22 13:33:26 | 只看该作者
全局:
Read N Characters Given Read4 II - Call multiple times

还没弄懂题目。。。
回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-23 12:35:35 | 只看该作者
全局:
本帖最后由 中心点 于 2019-4-26 14:02 编辑

4/22
  • Read N Characters Given Read4 II - Call multiple times
  • Remove duplicates from array
回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-24 01:46:50 | 只看该作者
全局:
本帖最后由 中心点 于 2019-4-24 09:00 编辑

4/23
1. number of digit ones  
2. 3sum (no sort)
3. Max Consecutive Ones III
4. Minimum Area Rectangle
5. Design Circular Queue
6. Search a 2D Matrix II
7. Range Sum Query 2D - Immutable
8. Subarray Sum Equals K
9. Random Pick with Weight
回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-24 09:01:00 | 只看该作者
全局:
need to review soon:
Search a 2D Matrix II
Design Circular Queue
Random Pick with Weight
回复

使用道具 举报

🔗
 楼主| 中心点 2019-4-25 14:02:01 | 只看该作者
全局:
本帖最后由 中心点 于 2019-4-26 14:01 编辑

4/24
  • Custom Sort String
  • Word Pattern
  • Word Pattern II
  • Walls and Gates
回复

使用道具 举报

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

本版积分规则

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