leetcode 121

leetcode 121
dp? my answer

class Solution {
public:int maxProfit(vector<int>& prices) {int bd=prices[0],sd=0;int max_num=0;for(int i=1;i!=prices.size();++i){sd=prices[i];if(sd<bd) bd=sd;else if(sd-bd>max_num)max_num=sd-bd;}return max_num;}
};

在这里插入图片描述
END

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421202.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

statcounter统计的浏览器市场占有率

Source: StatCounter Global Stats - Browser Market Share 转载于:https://www.cnblogs.com/Wayou/p/browser_market_share.html

1008. Elevator (20)

1008. Elevator (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator wil…

.net中的硬盘操作(针对Windows )

1&#xff0c;文件与文件夹的读取&#xff08;针对Windows &#xff09; 这是程序员的基本功。 做这种操作首先要引入一个命名空间 using System.IO I input 输入 O output 输出File.Create("C:\1.txt"); file是个静态类&#xff0c;里面有很多方法&#xff0c;多是…

1084. Broken Keyboard (20)

1084. Broken Keyboard (20) 时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueOn a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on scr…

ubuntu 10.4非法关机后上不了网

用的好好的ubuntu 10.4&#xff0c;非法关机后居然上不了网&#xff0c;右上角的网络图标也不见了&#xff0c;还以为是网卡问题&#xff0c;进入xp&#xff0c;发现一切正常&#xff0c;心里不断地诅咒ubuntu&#xff0c;该死的ubuntu&#xff0c;我windows还天天非法关机呢&a…

.net关于app.config的使用 对于自己的类库

类库中有 ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;则app.config 中 <connectionStrings><add name "conStr" connectionString " Data Source .;Initial Catalog ***;Integrated Security True"/>…

优秀设计师是如何炼成的,看搜狐如何做设计

《设计之下》终于上市了&#xff0c;回忆一下整个成书的过程&#xff0c;不得不佩服作者&#xff0c;从最开始的干净利落&#xff0c;到最终的细节的调整&#xff0c;作为编辑我对他们的认识逐渐加深&#xff0c;也慢慢了解了优秀设计师是如何炼成的。 这本书源于2012年12月份的…

1092. To Buy or Not to Buy (20)

1092. To Buy or Not to Buy (20) 时间限制100 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueEva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings …

.net多层结构 sql注入

1&#xff0c;功能单一型 解释&#xff1a;比如一个软件是由 界面部分 User Interface 代码逻辑 Business Logic Layer 数据库部分 Data Access Layer 组成。 但是为什么一个常见的软件要搞得这么复杂&#xff1f;为什么不能把以上三种融为一体。这样不就避免了 【中间件】的学…

Java中文字符所占的字节数

本文由广州疯狂软件java培训为你整理&#xff1a; Java语言中&#xff0c;中文字符所占的字节数取决于字符的编码方式&#xff0c;一般情况下&#xff0c;采用ISO8859-1编码方式时&#xff0c;一个中文字符与一个英文字符一样只占1个字节;采用GB2312或GBK编码方式时&#xff0c…

leetcode 102 C++AC

leetcode 102 我模仿二叉树的层序遍历的方法&#xff0c;自己写了一个。中间报错了&#xff0c;还特别去看了下这个文章https://blog.csdn.net/weixin_45799835/article/details/105780627 后来发现只是一个小错误&#xff0c;嘻嘻 class Solution { public:int maxDepth(Tree…

.net动态控件的使用(listview ,treeview,tabControl)

对于控件中显示的数据可能是不固定的。如果固定&#xff0c;数据发生了变化&#xff0c;又要重新设计&#xff0c;这样浪费成本&#xff0c;资源。 所以有用代码操作控件&#xff0c;自由度&#xff0c;可控度高。 1&#xff0c;树控件 //把 tv 作为全局变量 &#xff0c; 这是…

1120. Friend Numbers (20)

1120. Friend Numbers (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueTwo integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, …

泡茶看数据结构-临时(对象设计技术)

一.开场白 第二次《DATA STRUCTURES AND PROBLEM SOVLING WITH C》英文授课&#xff0c;让我产生英文写文章的念头。但是&#xff0c;慢慢开始参合英文吧。一下子写的话&#xff0c;怕写出来博客园首页都不敢收录了。^_^&#xff01;今天&#xff0c;从课堂和自己下午看总结下,…

分享几个可供学习,休闲的网站

设计的无限可能 http://seeseed.com 包含各种文案&#xff0c;创意短片&#xff0c;各种模板 http://addog.com 微软office plus/ppt 模板之王 http://officeplus.cn 中国数字科技馆 http://cdstm.cn 在线一键抠图 http://remove.bg 全球杂志 http://magazinelib.com 图片…

leetcode 112路径总和

leetcode 112 其实leetcode上的题解和评论都很好的&#xff0c;找题解不用到csdn来&#xff0c;我是想把自己做过的题都记录下来才来写这个 class Solution { public:bool hasPathSum(TreeNode* root,int targetSum) {if(!root) return false;if(root->leftnullptr&&am…

1083. List Grades (25)

1083. List Grades (25) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueGiven a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and outp…

1011. World Cup Betting (20)

1011. World Cup Betting (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueWith the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing b…

.net 日期总结,用于业务时间查询

//今天是这周的第几天&#xff0c;是个英文星期&#xff0c;可以转换成intstring a DateTime.Now.DayOfWeek.ToString();//今天//MessageBox.Show(Convert.ToInt32(DateTime.Now.DayOfWeek) "");昨天MessageBox.Show(DateTime.Now.AddDays(-1).ToString());//星期…