139. 单词拆分
public class WordBreak {
public boolean wordBreak(String s, List wordDict) {
Set wordSet = new HashSet(wordDict);
boolean[] dp = new boolean[s.length() + 1]; //Boolean会抛空指针
dp[0] = true;
for (int i = 1; i <= s.length(); i++) {
for (int j = 0; j < i; j++) {
if (dp[j] && wordSet.contains(s.substring(j, i))) {
dp[i] = true;
break;
}
}
}
return dp[s.length()];
}
}
152. 乘积最大子数组
class Solution {
public int maxProduct(int[] nums) {
int n = nums.length;
int[] dp = new int[n];
dp[0]=nums[0];
int result = nums[0], nmax = nums[0], nmin = nums[0];
for(int i = 1;i
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)