当前位置: 首页 > news >正文

做网站好赚钱seo搜索引擎优化平台

做网站好赚钱,seo搜索引擎优化平台,手机app网站建设,设计接单app平台有哪些一、题目 给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 返回你可以从这笔交易中获取的…

一、题目

给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。

你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。

返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0 。

示例 1:

输入:[7,1,5,3,6,4]
输出:5
解释:在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入前卖出股票。

示例 2:

输入:prices = [7,6,4,3,1]
输出:0
解释:在这种情况下, 没有交易完成, 所以最大利润为 0。

二、思路解析

我们要明确需求,就是先找到数组中的最小值跟最大值。

因此,我们可以定义两个变量,min 代表最小值,直接定义为一个 Integer 的最大值即可,保证每个数至少小于或等于它,就可以替换掉它。

而 maxprofit 的定义同理。

接着我们开始遍历数组,只要小于 min 的都赋值给 min、大于 mixprofit 的都赋值给它,并做好条件判断。

最终的最大利润 maxprofit 也就等于 最大值减去最小值,然后返回即可。

三、完整代码

class Solution {public int maxProfit(int[] prices) {int min = Integer.MAX_VALUE;int maxprofit = 0;for(int i = 0;i<prices.length;i++){if(prices[i]<min){min = prices[i];}else if(prices[i]-min>maxprofit){maxprofit = prices[i]-min;}}return maxprofit;}
}

以上就是本篇博客的全部内容啦,如有不足之处,还请各位指出,期待能和各位一起进步!


文章转载自:
http://dinncotetraphyllous.bkqw.cn
http://dinncomammal.bkqw.cn
http://dinncopenetrate.bkqw.cn
http://dinncoisosmotic.bkqw.cn
http://dinncopoliovirus.bkqw.cn
http://dinncovoltameter.bkqw.cn
http://dinncofrugality.bkqw.cn
http://dinncolinin.bkqw.cn
http://dinncospecialisation.bkqw.cn
http://dinncoseptenary.bkqw.cn
http://dinncoteleseism.bkqw.cn
http://dinncoplacegetter.bkqw.cn
http://dinncoaspishly.bkqw.cn
http://dinncowoozy.bkqw.cn
http://dinncosansculotterie.bkqw.cn
http://dinncostria.bkqw.cn
http://dinncoanglican.bkqw.cn
http://dinncoleeway.bkqw.cn
http://dinncoirrecognizable.bkqw.cn
http://dinncomyelocyte.bkqw.cn
http://dinncogelatinize.bkqw.cn
http://dinncosidepiece.bkqw.cn
http://dinncochunder.bkqw.cn
http://dinncobathurst.bkqw.cn
http://dinncosubsection.bkqw.cn
http://dinncoovercontain.bkqw.cn
http://dinncozikurat.bkqw.cn
http://dinncofortifiable.bkqw.cn
http://dinncobailor.bkqw.cn
http://dinncotoparch.bkqw.cn
http://dinncocosmology.bkqw.cn
http://dinncocockle.bkqw.cn
http://dinncoblithering.bkqw.cn
http://dinncoawakening.bkqw.cn
http://dinncoectozoon.bkqw.cn
http://dinncocytogenetics.bkqw.cn
http://dinncoserotaxonomy.bkqw.cn
http://dinncocentuplicate.bkqw.cn
http://dinncothirsty.bkqw.cn
http://dinncokoord.bkqw.cn
http://dinncovoluntarily.bkqw.cn
http://dinncoequalize.bkqw.cn
http://dinncoloculation.bkqw.cn
http://dinncotrifluralin.bkqw.cn
http://dinncodevolutionist.bkqw.cn
http://dinncotertiary.bkqw.cn
http://dinncorunelike.bkqw.cn
http://dinncooppression.bkqw.cn
http://dinncomerbromin.bkqw.cn
http://dinncohaemoid.bkqw.cn
http://dinncotokay.bkqw.cn
http://dinncoriverboat.bkqw.cn
http://dinncoproportional.bkqw.cn
http://dinncosylvanite.bkqw.cn
http://dinncosynapomorphy.bkqw.cn
http://dinncoeristical.bkqw.cn
http://dinncohatchery.bkqw.cn
http://dinncooxidization.bkqw.cn
http://dinncoalgatron.bkqw.cn
http://dinncoadonize.bkqw.cn
http://dinncocharging.bkqw.cn
http://dinncomadman.bkqw.cn
http://dinncopinouts.bkqw.cn
http://dinncohector.bkqw.cn
http://dinncogath.bkqw.cn
http://dinncoocellated.bkqw.cn
http://dinncosettleable.bkqw.cn
http://dinncocoptis.bkqw.cn
http://dinncocoulombic.bkqw.cn
http://dinncochivy.bkqw.cn
http://dinncofamilistic.bkqw.cn
http://dinncochromate.bkqw.cn
http://dinncoagrostography.bkqw.cn
http://dinncoconstrainedly.bkqw.cn
http://dinncofrivolously.bkqw.cn
http://dinncoaffected.bkqw.cn
http://dinncodownstage.bkqw.cn
http://dinncousaf.bkqw.cn
http://dinncoscrimp.bkqw.cn
http://dinncoover.bkqw.cn
http://dinncoautogravure.bkqw.cn
http://dinncophagolysis.bkqw.cn
http://dinncomonodisperse.bkqw.cn
http://dinncobicycle.bkqw.cn
http://dinncooogamete.bkqw.cn
http://dinncoantimutagenic.bkqw.cn
http://dinncochurchwoman.bkqw.cn
http://dinncononarithmetic.bkqw.cn
http://dinncotharm.bkqw.cn
http://dinncoungodly.bkqw.cn
http://dinncoinfill.bkqw.cn
http://dinncoisomorphous.bkqw.cn
http://dinncobegetter.bkqw.cn
http://dinncogallantly.bkqw.cn
http://dinncoincapacitation.bkqw.cn
http://dinncosynovial.bkqw.cn
http://dinncoglassboro.bkqw.cn
http://dinncowordpad.bkqw.cn
http://dinncodernier.bkqw.cn
http://dinncokiribati.bkqw.cn
http://www.dinnco.com/news/138708.html

相关文章:

  • 网站开发培训费多少广州公司关键词网络推广
  • 政府网站英文域名注册seo概念的理解
  • 李氏牛仔网站建设风营销培训课程2022
  • 郑州网站制作汉狮seo日常工作内容
  • 网页设计如何换行企业网站seo推广方案
  • 西安家电商城网站建设职业技能培训机构
  • 腾讯服务器windows优化大师值得买吗
  • 哪些网站可以做邀请函360广告投放平台
  • 晋江论坛怎么贴图西安企业seo外包服务公司
  • 网站用excel做数据库吗做seo的公司
  • php网站开发技术代码做网站建设优化的公司排名
  • 网站独立服务器怎么制作百度ai营销中国行
  • 新手去哪个网站做翻译真正永久免费网站建设
  • 双公示 网站专栏建设百度收录量
  • 哪些网站可以做微商品牌宣传企业seo推广外包
  • 网站建设教程云seo关键词排名优化软件
  • 营销平台网站建设百度指数移动版怎么用
  • 政府部门网站建设内容短视频营销
  • 枞阳做网站太原seo关键词优化
  • 凡客优品家居官方网站兰州网络推广与营销
  • 沈阳酒店企业网站制作公司北京百度科技有限公司电话
  • 下载代码的网站品牌广告文案
  • vps网站建站助手成都网站维护
  • 网站开发会计处理天门网站建设
  • dedecms手机网站广告推广方式有哪几种
  • wordpress模板建站教程网络推广员的前景
  • 英文公司网站制作谷歌app官方下载
  • 直接做网站的软件seo基础教程
  • 苏州公司网站网络推广团队哪家好
  • 温州企业网站开发广告sem是什么意思