二分查找,本身输入测试用例就是O(n)了,所以二分查找并没有意义,所以我是一边输入一边比对目标数的,一样AC
股票
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			String tmp[] = in.nextLine().split(",");
			int buy = Integer.parseInt(tmp[0]), max = 0;
			for (int i = 1; i < tmp.length; i++) {
				int now = Integer.parseInt(tmp[i]);
				if (now < buy) {
					buy = Integer.parseInt(tmp[i]);
				} else {
					max = Math.max(max, now - buy);
				}
			}
			System.out.println(max);
		}
		in.close();
	}
}