design:
elevator system design
algorithm:
1:two list to judge if they are intersected which means two lists have the same list node (same address)
2:one day's certain kind of stock's value is known ,please catulate the max profit when to buy and when to sell.
求捉鱼等概率的解决方案:
n条鱼一次从你身边游过,确保当第m条鱼游过时,你手中有任一条鱼的概率是1/m
1 当每k条鱼经过时候,捉住放在左手;(前面流过了k-1条鱼)
2 如果右手有鱼,则放掉左手的鱼,没有则把左手的鱼交换到右手;
左手没有鱼概率为1/k,所以手中有第k条鱼的概率是1/k;
右手有任意一条鱼(前面k-1条中的一条)概率为1/k,所以手中有前面k-1条中任意一条的概率也是1/k
所以手中此刻有任意一条鱼的概率是1/m.
编程:
N阶楼梯,每次可以爬1或者2阶,问有多少种上楼的方法?注意性能问题
循环2^N 或者随机数实现