。 | 45 | Jump Game II | 26.0% | Hard |
很好的题目。
https://discuss.leetcode.com/topic/3191/o-n-bfs-solution/2
85 | Maximal Rectangle | 26.1% | Hard |
这个解法真的是相当的好。
https://discuss.leetcode.com/topic/6650/share-my-dp-solution/2
233 | Number of Digit One | 27.3% | Hard |
这个解法非常好,也非常有技巧:
https://discuss.leetcode.com/topic/18054/4-lines-o-log-n-c-java-python
通过对某一个位置上面的1的个数累加,来完成。
57 | Insert Interval | 26.3% | Hard |
解法非常好。
http://www.cnblogs.com/charlesblc/p/6438698.html
37 | Sudoku Solver | 28.1% | Hard |
很好的解法:
https://discuss.leetcode.com/topic/11327/straight-forward-java-solution-using-backtracking
432 | All 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; };
很不错。用了stl里面的list,然后用了里面的iterator,可以方便的++,--,insert和erase。