继续过Hard题目.周五
。 | 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。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!