一开始的思路:
第一反应:建一个list,
新增:新增元素append到尾部
弹出:list尾部pop
top:取list尾部首元素
min:每次新进一个人,和当前min对比
问题:
如果当前的min弹出后,min变量没有记忆性,不知道之前存的min是多少
解决:
建一个存min的list,用法和stack一样,如果出队后,还是可以知道上一个最小值是多少
心が強い人なれるように
一开始的思路:
第一反应:建一个list,
新增:新增元素append到尾部
弹出:list尾部pop
top:取list尾部首元素
min:每次新进一个人,和当前min对比
问题:
如果当前的min弹出后,min变量没有记忆性,不知道之前存的min是多少
解决:
建一个存min的list,用法和stack一样,如果出队后,还是可以知道上一个最小值是多少
我的思路:
定义一个字典,
开始沥遍list
如果指向的数字 在字典里出现数 不等于1, 就让value=1(等于一,就加一)
然后沥遍字典,找到value等于1的位置,再读出key的数字
结果:速度太慢
solution:
没看到空间复杂度o(1)
异或逻辑运算:
待更新
题目很简单,但是有几个地方需要注意:
我的思路:
首先假设第一天肯定买进,然后从第二天开始看
情况一:如果第二天的价格低于第一天,那就以第二天的买价为准
以此类推
情况二:如果盈利天时,就开始计算之后每一天的差价,并记录最高价
每次发现有情况二发生,比较当前差价和上次计算差价,取其最大值
结论:8800ms 问题在情况2判断是 时间复杂度在o(n)级别
对比参考答案
发现盈利天时,将当天受益和当前最佳受益(初始值0,即平仓线)直接对比
如果当天收益更高,直接更新最佳受益计数
结论:60ms
总结:
条件一,找买入时机,条件二,找卖出时机
Background:
It is insane to build a table describing every attribute for huge a lot of entities, because there are many spareness in it.
Definition:
1. entity: the things to be described
2. attribute: ways or data to desribe the entity
3. value: the value of attribute
then:
1. a row is a fact
2. attribute and value pair is a fact describing an entity
In detail:
the entity is also like a array, which includes, in the clinical example, name and brief descpriton.
the attribute is cited from attribute definition table as a foreign key.
If you feel nervous when beginning to read books or do study, forgetting is the best answer. Of course, not to forget the things you are reading but to ignore any other stuff like clean memory in the computer field.
Only understand this point is not enough; it is also essential to feel the words as kind of sense as much as you can, like pictures as vivid and dynamic is better.