继续过Hard题目.周五

 

 #TitleEditorialAcceptanceDifficultyFrequency 
 。65Valid Number   12.6%Hard 
 。126Word Ladder II   13.6%Hard 
 。149Max Points on a Line   15.6%Hard 
 。146LRU Cache   16.0%Hard 
 。68Text Justification   18.1%Hard 
 。460LFU Cache   19.0%Hard 
 。44Wildcard Matching   19.0%Hard 
 。308Range Sum Query 2D - Mutable   19.8%Hard 
 。4Median of Two Sorted Arrays   20.8%Hard 
 。420Strong Password Checker   21.0%Hard 
 。273Integer to English Words   21.1%Hard 
 。30Substring with Concatenation of All Words   21.7%Hard 
 。440K-th Smallest in Lexicographical Order   22.1%Hard 
 。140Word Break II   22.2%Hard 
 。212Word Search II   22.2%Hard 
 。269Alien Dictionary   22.3%Hard 
 。174Dungeon Game   22.9%Hard 
 。214Shortest Palindrome   23.0%Hard 
 。446Arithmetic Slices II - Subsequence   23.0%Hard 
 。32Longest Valid Parentheses   23.1%Hard 
 。295Find Median from Data Stream   23.3%Hard 
 。132Palindrome Partitioning II   23.4%Hard 
 。10Regular Expression Matching   23.6%Hard 
 。76Minimum Window Substring   23.8%Hard 
 。188Best Time to Buy and Sell Stock IV   23.8%Hard 
 。321Create Maximum Number   23.9%Hard 
 。135Candy   23.9%Hard 
 。335Self Crossing   23.9%Hard 
 。97Interleaving String   23.9%Hard 
 。391Perfect Rectangle   24.2%Hard 
 。158Read N Characters Given Read4 II - Call multiple times   24.4%Hard 
 。466Count The Repetitions   24.6%Hard 
 。336Palindrome Pairs   24.7%Hard 
 。41First Missing Positive   24.9%Hard 
 。124Binary Tree Maximum Path Sum   25.0%Hard 
 。224Basic Calculator   25.5%Hard 
 。218The Skyline Problem   25.5%Hard 
 。84Largest Rectangle in Histogram   25.6%Hard 
 。23Merge k Sorted Lists   25.9%Hard 
 。45Jump Game II   26.0%Hard 
 。85Maximal Rectangle   26.1%Hard 
 。57Insert Interval   26.3%Hard 
 。138Copy List with Random Pointer   26.6%Hard 
 。233Number of Digit One   27.3%Hard 
 。381Insert Delete GetRandom O(1) - Duplicates allowed   28.0%Hard 
 。37Sudoku Solver   28.1%Hard 
 。432All O`one Data Structure   28.2%Hard 
 。87Scramble String   28.3%Hard 
 。123Best Time to Buy and Sell Stock III   28.3%Hard 
 。56Merge Intervals   28.4%Hard 
 。282Expression Add Operators   28.5%Hard 
 。316Remove Duplicate Letters   28.6%Hard 
 164Maximum Gap   28.6%Hard 
 99Recover Binary Search Tree   28.7%Hard 
 327Count of Range Sum   28.9%Hard 
 51N-Queens   29.0%Hard 
 25Reverse Nodes in k-Group   29.7%Hard 
 472Concatenated Words   30.1%Hard 
 465Optimal Account Balancing   30.1%Hard 
 248Strobogrammatic Number III   30.5%Hard 
 72Edit Distance   30.6%Hard 
 115Distinct Subsequences   30.6%Hard 
 403Frog Jump   30.9%Hard 
 411Minimum Unique Word Abbreviation   31.1%Hard 
 239Sliding Window Maximum   31.4%Hard 
 330Patching Array   31.5%Hard 
 297Serialize and Deserialize Binary Tree   31.6%Hard 
 354Russian Doll Envelopes   31.8%Hard 
 358Rearrange String k Distance Apart   31.8%Hard 
 33Search in Rotated Sorted Array   31.9%Hard 
 363Max Sum of Rectangle No Larger Than K   32.1%Hard 
 410Split Array Largest Sum   32.2%Hard 
 480Sliding Window Median   33.1%Hard 
 317Shortest Distance from All Buildings   33.3%Hard 
 117Populating Next Right Pointers in Each Node II   33.5%Hard 
 315Count of Smaller Numbers After Self   33.5%Hard 
 301Remove Invalid Parentheses   34.5%Hard 
 42Trapping Rain Water   35.3%Hard 
 128Longest Consecutive Sequence   35.3%Hard 
 329Longest Increasing Path in a Matrix   35.4%Hard 
 407Trapping Rain Water II   35.6%Hard 
 154Find Minimum in Rotated Sorted Array II   36.2%Hard 
 265Paint House II   37.1%Hard 
 272Closest Binary Search Tree Value II   37.6%Hard 
 291Word Pattern II   37.7%Hard 
 305Number of Islands II   38.1%Hard 
 380Insert Delete GetRandom O(1)   38.4%Hard 
 145Binary Tree Postorder Traversal   38.4%Hard 
 340Longest Substring with At Most K Distinct Characters   38.6%Hard 
 352Data Stream as Disjoint Intervals   38.9%Hard 
 159Longest Substring with At Most Two Distinct Characters   39.7%Hard 
 312Burst Balloons   41.6%Hard 
 287Find the Duplicate Number   41.8%Hard 
 425Word Squares   41.9%Hard 
 52N-Queens II   42.8%Hard 
 302Smallest Rectangle Enclosing Black Pixels   44.0%Hard 
 471Encode String with Shortest Length   44.2%Hard 
 296Best Meeting Point   50.4%Hard

 

 。45Jump Game II   26.0%Hard

很好的题目。

https://discuss.leetcode.com/topic/3191/o-n-bfs-solution/2

 

85Maximal Rectangle   26.1%Hard

这个解法真的是相当的好。

https://discuss.leetcode.com/topic/6650/share-my-dp-solution/2

 

233Number of Digit One   27.3%Hard

这个解法非常好,也非常有技巧:

https://discuss.leetcode.com/topic/18054/4-lines-o-log-n-c-java-python

通过对某一个位置上面的1的个数累加,来完成。

 

 

57Insert Interval   26.3%Hard

解法非常好。

http://www.cnblogs.com/charlesblc/p/6438698.html

 

37Sudoku Solver   28.1%Hard

很好的解法:

https://discuss.leetcode.com/topic/11327/straight-forward-java-solution-using-backtracking

 

432All O`one Data Structure   28.2%Hard

我也有大致的思路。这个里面的代码写的真是非常的精巧。

https://discuss.leetcode.com/topic/63827/c-solution-with-comments

class AllOne {
public:

    void inc(string key) {
        
        // If the key doesn't exist, insert it with value 0.
        if (!bucketOfKey.count(key))
            bucketOfKey[key] = buckets.insert(buckets.begin(), {0, {key}});
            
        // Insert the key in next bucket and update the lookup.
        auto next = bucketOfKey[key], bucket = next++;
        if (next == buckets.end() || next->value > bucket->value + 1)
            next = buckets.insert(next, {bucket->value + 1, {}});
        next->keys.insert(key);
        bucketOfKey[key] = next;
        
        // Remove the key from its old bucket.
        bucket->keys.erase(key);
        if (bucket->keys.empty())
            buckets.erase(bucket);
    }

    void dec(string key) {

        // If the key doesn't exist, just leave.
        if (!bucketOfKey.count(key))
            return;

        // Maybe insert the key in previous bucket and update the lookup.
        auto prev = bucketOfKey[key], bucket = prev--;
        bucketOfKey.erase(key);
        if (bucket->value > 1) {
            if (bucket == buckets.begin() || prev->value < bucket->value - 1)
                prev = buckets.insert(bucket, {bucket->value - 1, {}});
            prev->keys.insert(key);
            bucketOfKey[key] = prev;
        }
        
        // Remove the key from its old bucket.
        bucket->keys.erase(key);
        if (bucket->keys.empty())
            buckets.erase(bucket);
    }

    string getMaxKey() {
        return buckets.empty() ? "" : *(buckets.rbegin()->keys.begin());
    }
    
    string getMinKey() {
        return buckets.empty() ? "" : *(buckets.begin()->keys.begin());
    }

private:
    struct Bucket { int value; unordered_set<string> keys; };
    list<Bucket> buckets;
    unordered_map<string, list<Bucket>::iterator> bucketOfKey;
};
View Code

很不错。用了stl里面的list,然后用了里面的iterator,可以方便的++,--,insert和erase。

 

转载于:https://www.cnblogs.com/charlesblc/p/6437493.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值