二分查找,本身输入测试用例就是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(); } }
点赞 2

相关推荐

02-04 17:01
南昌大学 Java
牛客96763241...:拿插件直接投就完了,这玩意看运气的
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务