121. Best Time to Buy and Sell Stock
来源:互联网 发布:mac在哪里下载软件 编辑:程序博客网 时间:2024/06/10 21:14
题目大意:给定一个一直序列,求出最大差值,注意只能由后面的数减前面的数。例如:
[7, 1, 5, 3, 6, 4]
6-1,输出答案5;
[7, 6, 4, 3, 1]输出0.
基本思路:暴力解法,需要o(n2)的时间复杂度。
优化解法,时间复杂度o(n):
0 0
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time To Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- 4 Have Fun with Numbers
- linux下cpio.gz文件的解压方法
- 计算在UITableView中的UICollectionView的高度(自适应)(iOS10可用)
- 将从数据库中读出的带html标签的数据转化为正常的带样式的文字
- Yii 框架里数据库操作详解-[增加、查询、更新、删除的方法 'AR模式']
- 121. Best Time to Buy and Sell Stock
- 'com.android.support:support-annotations' 问题解决方法
- 新手快速入门Docker最新版管理工具
- Longest Increasing Path in a Matrix
- 安卓学习笔记---完美解决Android的WebView加载失败(404,500),显示的自定义视图
- linux初学
- 初始android
- 2PC
- 详细介绍Linux shell脚本基础学习