1.
public static int judge(int n){ int[] dp = new int[n]; dp[0] = 1; int temp2 = 0, temp3 = 0, temp5 = 0; for (int i=1;i<n;i++){ dp[i] = Math.min(dp[temp2 ] * 2, Math.min(dp[temp3] * 3, dp[temp5] * 5)); if (dp[i] / dp[temp2] == 2)temp2++; if (dp[i] / dp[temp3] == 3)temp3++; if (dp[i] / dp[temp5] == 5)temp5++; } return dp[n-1]; }2.
public static List judge(){ List<List<Integer>> lists = new ArrayList<>(); Stack<Integer> stack = new Stack<>(); for (int a = 0; a<= 9;a++){ stack.push(a); for (int b = 0; b<= 9; b++){ stack.push(b); for (int c = 0; c <= 9;c++){ stack.push(c); for (int d = 0; d <= 9;d++){ stack.push(d); if (a*1000 + b*100 + c*10 + d + b*1000 + c*100 + d*10 + a == 8888){ lists.add(new ArrayList<>(stack)); } stack.pop(); } stack.pop(); } stack.pop(); } stack.pop(); } return lists; }
3.
public static long judge(long[] nums){ if (nums == null)return 0; int len = nums.length; if (len == 0)return 0; if (len == 1)return nums[0]; long[] dp = new long[len]; dp[0] = nums[0]; dp[1] = Math.max(dp[0],nums[1]); for (int i = 2;i < len;i++){ dp[i] = Math.max(dp[i-2] + nums[i], Math.max(dp[i-1],nums[i])); } return dp[len-1]; }
全部评论
(1) 回帖