左耳听风ARTS第五周

Algorithms

121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Note that you cannot sell a stock before you buy one.

Example 1:

Input: [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
             Not 7-1 = 6, as selling price needs to be larger than buying price.
Example 2:

Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.

Solution 1: leetcode上的思路—类似最大子数列问题,类似kadane’s algorithm算法。

class Solution {
     public int maxProfit(int[] prices) {
        int maxCur = 0;int maxSofar = 0;
         for(int i = 1;i < prices.length;i++){
             maxCur = Math.max(0,maxCur+= prices[i]-prices[i -1]);
             maxSofar = Math.max(maxCur,maxSofar);
         }
         return maxSofar;
    }
}

Review

ServerSide checklist
对于web应用来说,在发布产品之前,服务器端需要遵守的一系列规则,简单总结如下:
1、系统要有弹性:不能让应用局部发生的错误影响或者扩散到整个系统,系统在高负载的情况下不会挂掉。
2、部署对用户透明:应用添加节点的时候不会影响到当前在线的用户。
3、系统要有监控:http请求超时、500错误、服务重启、服务器资源耗尽。
4、系统测试:网络分区测试、压力测试。
5、数据备份:从备份数据恢复系统所有数据。
6、系统安全:TLS、OWASP TOP 10 Vulnerabilities、HTTP security headers。

Tips

1、网络协议第三层:网络层。网络层是无状态的,通过网关或者路由器等第三层设备,提供路由和寻址的功能。
2、ICMP协议和IP协议都属于第三层。ICMP报文有很多类型,常用的类型有主动请求和主动应答,ping就是一种主动请求,并且获取主动应答的ICMP协议。
3、TTL(time to live):数据包在网络中的生命周期。设计目的是防止数据包因不正确的路由造成无限的循环而无法送达及耗尽网络资源。
4、traceroute:设计目的是追踪数据包在IP网络中的路由路径。实现原理是设置特殊的TTL,选择一个不可能的值作为UDP端口号(大于30000),发送UDP数据报。目的主机会产生一份“端口不可达”的错误ICMP报文,如果数据报没有到达,则可能是超时。

Share

线程池的拒绝策略设计的简单理解。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值