zoukankan      html  css  js  c++  java
  • 股票最大利润

    package JianZhioffer;
    // 假设把某股票的价格按照时间先后顺序存储在数组中,请问买卖该股票一次可能获得的最大利润是多少?
    
    
    public class test63 {
        public static void main(String[] args) {
            int []prices={7,6,4,3,1};
            System.out.println(maxProfit(prices));    
        }
        public static int maxProfit(int[] prices) {
            if(prices.length==0){
                return 0;
            }
            int []dp=new int[prices.length];
            int cost=Integer.MAX_VALUE,profit=0;
            for(int i=0;i<prices.length;i++){
                cost=Math.min(cost, prices[i]);
                profit=Math.max(profit, prices[i]-cost);
            }
            return profit;
        }
    
        
    }
  • 相关阅读:
    flush logs
    slave-skip-errors,sql_slave_skip_counter
    稀饭
    table
    profiles
    索引使用规范
    innodb_rollback_on_timeout
    mysql账号管理
    跨库复制
    linux.sh
  • 原文地址:https://www.cnblogs.com/jieyi/p/14201086.html
Copyright © 2011-2022 走看看