zoukankan      html  css  js  c++  java
  • Best Time to Buy and Sell Stock

     1 public class Solution {
     2     public int maxProfit(int[] prices) {
     3         // IMPORTANT: Please reset any member data you declared, as
     4         // the same Solution instance will be reused for each test case.
     5         if(prices == null||prices.length == 0)
     6             return 0;
     7         int result = 0;
     8         int min = prices[0];
     9         for(int i = 0; i < prices.length; i++)
    10         {
    11             if(prices[i] < min)
    12                 min = prices[i];
    13             result = Math.max(result, prices[i]-min);
    14         }
    15         return result;
    16     }
    17 }
  • 相关阅读:
    【Coreforces 1253E】
    计数专题乱做
    PKUWC2020乱做
    多项式板子
    notepad
    2021.4.9
    2021.4.8
    2021.3.31
    2021.3.26
    2021.3.25
  • 原文地址:https://www.cnblogs.com/jasonC/p/3440236.html
Copyright © 2011-2022 走看看