您的位置:首页 > 娱乐 > 八卦 > 静态网页制作的企业_阿里云国际站官网_建网站的软件有哪些_百度推广代理怎么加盟

静态网页制作的企业_阿里云国际站官网_建网站的软件有哪些_百度推广代理怎么加盟

2024/10/5 23:19:56 来源:https://blog.csdn.net/zzhnwpu/article/details/142411278  浏览:    关键词:静态网页制作的企业_阿里云国际站官网_建网站的软件有哪些_百度推广代理怎么加盟
静态网页制作的企业_阿里云国际站官网_建网站的软件有哪些_百度推广代理怎么加盟

今日任务

279.完全平方数
139.单词拆分

279.完全平方数

题目链接: . - 力扣(LeetCode)

class Solution {public int numSquares(int n) {int[] dp = new int[n + 1];Arrays.fill(dp, Integer.MAX_VALUE);int item = (int)Math.sqrt(n);dp[0] = 0;for (int i = 1; i <= item; i++) {for (int j = 0; j <= n; j++) {if (j >= i * i && dp[j - i * i] != Integer.MAX_VALUE) {dp[j] = Math.min(dp[j], dp[j - i * i] + 1);}}}return dp[n];}
}

139.单词拆分

题目链接: . - 力扣(LeetCode)

class Solution {public boolean wordBreak(String s, List<String> wordDict) {HashSet<String> set = new HashSet<>(wordDict);boolean[] dp = new boolean[s.length() + 1];dp[0] = true;for (int i = 1; i <= s.length(); i++) {for (int j = 0; j <= i; j++) {if (set.contains(s.substring(j, i)) && dp[j] == true) {dp[i] = true;}}}for (int i = 0; i < dp.length; i++) {System.out.println("dp " + i + " is: " + dp[i]);}return  dp[s.length()];}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com