zoukankan      html  css  js  c++  java
  • 149_best-time-to-buy-and-sell-stock

    /*
    @Copyright:LintCode
    @Author:   Monster__li
    @Problem:  http://www.lintcode.com/problem/best-time-to-buy-and-sell-stock
    @Language: Java
    @Datetime: 17-03-02 12:15
    */

    public class Solution {
        /**
         * @param prices: Given an integer array
         * @return: Maximum profit
         */
        public int maxProfit(int[] prices) {
            // write your code here
              int maxProfit=0,i,j;
      for(i=0;i<prices.length-1;i++)
      {
       for(j=i+1;j<prices.length;j++)
       {
        if(prices[j]-prices[i]>maxProfit)
        {
         maxProfit=prices[j]-prices[i];
        }
       }
      }
      return maxProfit;
        }
    }

  • 相关阅读:
    Middleware
    Languages
    Errors
    Config
    CLI Console
    Linux远程复制文件
    CentOS下安装Gitlab
    Maven_POM配置结构
    Maven_POM配置详解
    MySQL索引背后的数据结构及算法原理
  • 原文地址:https://www.cnblogs.com/liyuquan/p/6518925.html
Copyright © 2011-2022 走看看