Algorithm
lc2034_股票价格波动
思路:
用一个最大最小值记录最大最小值(val,也可以用有序队列multimap记录一排值,或者大小优先队列),然后用无序的unordered_map返回最大时间的值(也就是要记录一个最大的key)为最新股价
最大最小值一直用max,min维护是错误的思路,因为股价会波动,不能用历史的最大最小值
错误代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| class StockPrice { map<int, int> time2price; int _max, _min; public: StockPrice() { time2price.clear(); _max = -1; _min = (int)1e9; } void update(int timestamp, int price) { _max = max(_max, price); _min = min(_min, price); time2price[timestamp] = price; } int current() { return time2price.rbegin()->second; } int maximum() { return _max; } int minimum() { return _min; } };
|
正确代码
链接:https://leetcode-cn.com/problems/stock-price-fluctuation/solution/gu-piao-jie-ge-bo-dong-by-leetcode-solut-rwrb/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| class StockPrice { public: StockPrice() { this->maxTimestamp = 0; } void update(int timestamp, int price) { maxTimestamp = max(maxTimestamp, timestamp); int prevPrice = timePriceMap.count(timestamp) ? timePriceMap[timestamp] : 0; timePriceMap[timestamp] = price; if (prevPrice > 0) { auto it = prices.find(prevPrice); if (it != prices.end()) { prices.erase(it); } } prices.emplace(price); } int current() { return timePriceMap[maxTimestamp]; } int maximum() { return *prices.rbegin(); } int minimum() { return *prices.begin(); } private: int maxTimestamp; unordered_map<int, int> timePriceMap; multiset<int> prices; };
|
Review
【TED演讲】网络犯罪究竟从何而来?
共享病毒库,共享防护手段,从而让黑客无法攻击下一个受害者,这样就防止了网络犯罪,但是很多公司都是要靠这个赚钱
所以这样的事情应该很难做,他们宁愿成为网络犯罪的共犯,也要自己赚钱,这无可厚非,需要一种好的激励方案
Tips
NFS配置固定端口并设置防火墙规则
Share
docker容器改静态ip
自己网上找了,没有明确的步骤
只知道可以改配置,操作一把,成功
systemctl stop docker
docker info | grep "Docker Root Dir"
vim ${docker_root}/containers/1b1xxxxx/config.v2.json
(修改ip)
systemctl start docker