您的位置:首页 > 游戏 > 手游 > 网上推广平台怎么收费_广东制作公司网站_seo的主要内容_厦门网站的关键词自动排名

网上推广平台怎么收费_广东制作公司网站_seo的主要内容_厦门网站的关键词自动排名

2025/2/24 8:56:25 来源:https://blog.csdn.net/zsysingapore/article/details/145693193  浏览:    关键词:网上推广平台怎么收费_广东制作公司网站_seo的主要内容_厦门网站的关键词自动排名
网上推广平台怎么收费_广东制作公司网站_seo的主要内容_厦门网站的关键词自动排名

1.题目描述
请添加图片描述
2.思路
思路1:
请添加图片描述

在这里插入图片描述
请添加图片描述
请添加图片描述

3.java代码实现

class Solution {public int maxProfit(int[] prices) {// //初始化最小价格为最大值,最大利润为0//    int minPrice=Integer.MAX_VALUE;//    int maxProfit=0;//    //遍历价格数组//    for (int price : prices)//    {//     //如果当前价格更低,更新最小价格//     if(price<minPrice)//     {//         minPrice = price;//     }//     // 计算当前卖出时的利润//     else//     {//         int profit=price-minPrice;//         // 更新更大利润//         if(profit>maxProfit)//         {//             maxProfit= profit;//         }//     }//    }//    return maxProfit;if(prices==null ||prices.length<2){return 0;}int minPrice=prices[0];// 初始化最小价格为第一个元素int maxPofit=0;for(int i=1;i<prices.length;i++){// 如果当前价格比最小价格大,计算利润int  profit=prices[i]-minPrice;// 更新最小价格minPrice = Math.min(minPrice,prices[i]);// 更新最大利润 maxPofit = Math.max(maxPofit,profit);}return maxPofit;}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com