这些日子笨蛋一直研究股票,经过调研,终于发现xxx公司股票规律,更可喜的是 笨蛋推算出这家公司每天的股价,为了防止别人发现他的秘密。他决定对于这家公司的 股票最多买一次,现在笨蛋已经将股票价格列了出来。(这已经不是笨蛋的难题了,他已经解决 呵 呵)。只想难为难为你呀,从股票价格表上,你能算出笨蛋的每股股票最多能赚多少钱吗?
输入 第一行一个n,表示n天(小于100000) 第二行 给出n天每股的价格 输出 每股最多赚多少钱 样例输入 4 947 267 359 771 7 669 735 322 794 397 565 181 样例输出 504 472 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int times = scanner.nextInt(); int arr[] = new int[times]; int max = -99999999; int min = 99999999; for (int i = 0; i < arr.length; i++) { arr[i] = scanner.nextInt(); if (i >= 1) { min = Math.min(min, arr[i - 1]); max = Math.max(max, arr[i] - min); } } System.out.println(max); } } }