好未来笔试题目
好未来笔试第五题,数组越界,只过了85%,求大佬找茬。
import java.util.*; public class Main5 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int[] nums = new int[101]; String[] temp = scanner.nextLine().split(" "); for (int i = 0; i < temp.length; i++) nums[i] = new Integer(temp[i]); int size = temp.length; if (size == 0) { System.out.println(0); System.exit(0); } int[] dp = new int[size]; dp[0] = nums[0]; int ans = dp[0]; for (int i = 1; i < size; i++) { dp[i] = nums[i]; for (int j = 0; j < i; j++) { if (nums[j] < nums[i]) dp[i] = Math.max(dp[i], dp[j] + nums[i]); } ans = Math.max(ans, dp[i]); } System.out.println(ans); } }#笔试题目##Java##好未来#