继续过Hard题目.周五
2024-08-28 04:47:29
。 | 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(), {, {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 + )
next = buckets.insert(next, {bucket->value + , {}});
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 > ) {
if (bucket == buckets.begin() || prev->value < bucket->value - )
prev = buckets.insert(bucket, {bucket->value - , {}});
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。
最新文章
- Guava学习-缓存
- JDK中的native2ascii命令详解
- HDU 2577 How to Type(dp题)
- 。。。HibernateTemplate与Session。。。
- Mysql配置文件my.cnf解析
- 使用公钥登录SSL
- web工程调用hadoop集群1.2
- Python 修炼2
- 报错信息 The jsp:param action must not be used outside the jsp:include, jsp:forward, or jsp:params elements 的原因及解决办法
- javascript中的null,对象系统还是非对象系统?
- 利用matplotlib库和numpy库画数学图形
- Git多个SSH KEYS解决方案(含windows自动化、TortoiseGit、SourceTree等)
- DeepLearning.ai-Week3-Autonomous driving-Car detection
- MNIST数据可视化
- Oozie分布式工作流——从理论和实践分析使用节点间的参数传递
- topcoder srm 415 div1
- 第七次Scrum冲刺
- [LeetCode_105]Construct Binary Tree from Preorder and Inorder Traversal
- [oldboy-django][2深入django]FBV + CBV + 装饰器
- JLOI2018 日志
热门文章
- Python及相应软件安装
- Map的四种遍历方法
- 【henuacm2016级暑期训练-动态规划专题 B】Coloring Trees
- HDU 4301 Contest 1
- [CSS3] Create Dynamic Styles with CSS Variables
- bzoj3173: [Tjoi2013]最长上升子序列(树状数组+二分倒推)
- m_Orchestrate learning system---十八、mo项目的启示是什么
- mount ntfs 失败解决办法
- Python基本语法(基于3.x)
- Android Handling back press when using fragments in Android