摘要:
首先暴力搜索: public final int maxSubArray1(int[] nums) { int max = Integer.MIN_VALUE; for (int i = 0; i < nums.length; i++) { for (int j = 0; j < nums.leng 阅读全文
摘要:
* @Description 将一条绳子剪成任意 m 段,m 大于 1 ,求最大积 * 决定问题规模的参数为绳子的长度 n * 按 n 进行分治,G( n ) 为长度为 n 的绳子分割后可得的最大积,可列出状态转移方程: * G( n ) = max { G(n-1)*1 , G(n-2)*2... 阅读全文
摘要:
最开始使用 DP ,因为题目中给的问题空间范围较大,缓存使用数组的话对连续的内存空间要求过高。故采用 hash 表做缓存: public int maxScore(int[] cardPoints, int k) { int length = cardPoints.length; Map<Strin 阅读全文