上一页 1 ··· 74 75 76 77 78 79 80 81 82 ··· 114 下一页
摘要: Java实现如下: public class Solution { public int coinChange(int[] coins, int amount) { if (amount == 0) return 0; int[] dp = new int[amount + 1]; dp[0] = 阅读全文
posted @ 2018-10-14 20:03 Sempron2800+ 阅读(205) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int MinAddToMakeValid(string S) { Stack ST = new Stack(); foreach (var s in S) { if (s.Equals('(... 阅读全文
posted @ 2018-10-14 19:54 Sempron2800+ 阅读(108) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int[] SortArrayByParityII(int[] A) { var len = A.Length; int[] ODD = new int[len / 2];//奇数1,3,5,7,9 int[] EVEN =... 阅读全文
posted @ 2018-10-14 19:43 Sempron2800+ 阅读(114) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: ListNode* sortList(ListNode* head) { multimap mul; while(head){ mul.insert(make_pair(head->val,head)); head=head->next; } ... 阅读全文
posted @ 2018-10-14 00:31 Sempron2800+ 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 补充另一种写法: 参考:https://leetcode.com/problems/partition-equal-subset-sum/discuss/90592/01-knapsack-detailed-explanation 先上一张图:测试数据为nums=[1,3,3,5],判断是否可以分割 阅读全文
posted @ 2018-10-14 00:25 Sempron2800+ 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 补充一个DFS遍历,然后倒叙组装成类似链表的解决方案,使用python实现: python的递归实现: 阅读全文
posted @ 2018-10-12 18:48 Sempron2800+ 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 使用动态规划,下面的代码可以通过210个测试,最后1个(第211个)会超时。说明思路是正确的,但是其中有一些是无效的计算。 再提供网上AC的参考实现: 再补充一个: 阅读全文
posted @ 2018-10-12 16:18 Sempron2800+ 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 补充一个python版本: dp是二维数组,每一个元素表示:从起点[0][0]开始,到当前单元格,最小的路径长度。 由于只能向“右”和“下”移动,而且没有负的权值。 因此, 第一行只能按照从左到右顺序,才能获得最小。 第一列,只能按照从上到下顺序,才能获得最小。 而其他单元格,可能有两种策略: 策略 阅读全文
posted @ 2018-10-12 14:25 Sempron2800+ 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 参考另外一个python的实现,解释的比较容易懂,代码思路和上面的是一样的。 定义二维数组,table进行动态规划的记录。table[i][j]表示字符串s中,下标i到下标j之间的字符是否是回文字符,true表示:是回文;false表示:不是回文。 10~12行,第一次循环,将对角线上元素进行标记, 阅读全文
posted @ 2018-10-12 14:03 Sempron2800+ 阅读(187) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: string decodeString(string s) { stack chars; stack nums; string res; int num = 0; for (char c: s) { if (isdig... 阅读全文
posted @ 2018-10-12 09:04 Sempron2800+ 阅读(138) 评论(0) 推荐(0) 编辑
上一页 1 ··· 74 75 76 77 78 79 80 81 82 ··· 114 下一页