随笔分类 -  leetcode

上一页 1 ··· 9 10 11 12 13 14 下一页
摘要:https://leetcode.com/problems/mini-parser/ /** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * public i... 阅读全文
posted @ 2016-08-28 23:31 blcblc 阅读(331) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/shuffle-an-array/ public class Solution { int [] origNums; int [] shufNums; java.util.Random rd; public Solution(int[] nums) { origNums = nums... 阅读全文
posted @ 2016-08-28 16:05 blcblc 阅读(161) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/ransom-note/ public class Solution { public boolean canConstruct(String ransomNote, String magazine) { char[] chRan = ransomNote.toCharArray(); char... 阅读全文
posted @ 2016-08-28 12:10 blcblc 阅读(152) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/linked-list-random-node/ // Using Reservoir sampling algorithm // https://discuss.leetcode.com/topic/53812/using-reservoir-sampling-o-1-space-o-n-time-complexity-c/2 /... 阅读全文
posted @ 2016-08-28 11:24 blcblc 阅读(212) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/ public class RandomizedCollection { ArrayList nums; HashMap> locs; java.util.Random rand; /** Initialize... 阅读全文
posted @ 2016-08-27 23:58 blcblc 阅读(350) 评论(0) 推荐(0)
摘要:// 参考了下面一些讨论的解法 // https://discuss.leetcode.com/topic/53235/java-with-hashtable-arraylist/2 class RandomizedSet { vector vec; unordered_map umap; public: /** Initialize your data structu... 阅读全文
posted @ 2016-08-04 22:59 blcblc 阅读(267) 评论(0) 推荐(0)
摘要://有很多讨论,比如 // https://discuss.leetcode.com/topic/52865/my-solution-using-binary-search-in-c // https://discuss.leetcode.com/topic/52912/binary-search-heap-and-sorting-comparison-with-concise-code-and... 阅读全文
posted @ 2016-08-02 14:41 blcblc 阅读(240) 评论(0) 推荐(0)
摘要:#include class Solution { unordered_map dp_map; vector vec; int func(int target) { if (dp_map.find(target) != dp_map.end()) { return dp_map[target]; ... 阅读全文
posted @ 2016-08-01 15:22 blcblc 阅读(193) 评论(0) 推荐(0)
摘要:// 参考了:https://discuss.leetcode.com/topic/51893/two-solutions-one-is-dp-the-other-is-greedy-8-lines // 另有:https://discuss.leetcode.com/topic/51946/very-simple-java-solution-with-detail-explanation c... 阅读全文
posted @ 2016-08-01 14:06 blcblc 阅读(407) 评论(0) 推荐(0)
摘要:// https://discuss.leetcode.com/topic/51353/simple-dp-solution-with-explanation // https://en.wikipedia.org/wiki/Minimax // 开始我的思路有问题,我是先选择区间,最后收敛到结果数 // 实际上work的思路是,先选择数字,再走向某个区间,然后取两个区间中的更大值 class... 阅读全文
posted @ 2016-07-18 14:50 blcblc 阅读(163) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/guess-number-higher-or-lower/ 阅读全文
posted @ 2016-07-14 13:29 blcblc 阅读(270) 评论(0) 推荐(0)
摘要:// https://discuss.leetcode.com/topic/50527/java-10ms-solution-no-priority-queue class Solution { public: vector> kSmallestPairs(vector& nums1, vector& nums2, int k) { sort(nums1.begin()... 阅读全文
posted @ 2016-07-10 15:00 blcblc 阅读(214) 评论(0) 推荐(0)
摘要:// https://discuss.leetcode.com/topic/50489/c-clean-and-short-solution class Solution { int base = 1337; int powMod(int a, int b) { a %= base; int result = 1; for (in... 阅读全文
posted @ 2016-07-10 14:10 blcblc 阅读(194) 评论(0) 推荐(0)
摘要:// refer to // https://leetcode.com/discuss/111582/java-simple-easy-understand-solution-with-explanation class Solution { public: int getSum(int a, int b) { //int tmp_sum = a ^ b; // a x... 阅读全文
posted @ 2016-06-30 17:31 blcblc 阅读(204) 评论(0) 推荐(0)
摘要:用了两种方法: 31 / 31 test cases passed. Accepted Runtime: 261 ms 开始用的下面这种方法,超时了: 阅读全文
posted @ 2016-06-28 14:30 blcblc 阅读(679) 评论(0) 推荐(0)
摘要:这道题目的循环里面的那个递推的式子很巧妙,能够帮助循环快速收敛。 阅读全文
posted @ 2016-06-27 15:06 blcblc 阅读(155) 评论(0) 推荐(0)
摘要:以下这个解法也是参考了一些讨论: https://leetcode.com/discuss/110235/c-solution-using-euclidean-algorithm 还有这个解释原理的,没有看懂:https://leetcode.com/discuss/110525/a-little- 阅读全文
posted @ 2016-06-27 14:45 blcblc 阅读(311) 评论(0) 推荐(0)
摘要:根据上一篇文章提到的参考文档: https://leetcode.com/discuss/109749/accepted-c-codes-with-explanation-and-references 我实现的解法,用了一个sum_max,不再另设res。 27 / 27 test cases pa 阅读全文
posted @ 2016-06-27 14:22 blcblc 阅读(305) 评论(0) 推荐(0)
摘要:今天的一道题目: https://leetcode.com/problems/max-sum-of-sub-matrix-no-larger-than-k/ 有难度。这一类题目很有代表性。 搜到这个网址有针对一维数组的求和的按照时间复杂度一步步优化的过程,讲的很不错: http://www.cnbl 阅读全文
posted @ 2016-06-27 13:39 blcblc 阅读(1000) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/count-numbers-with-unique-digits/ class Solution { public: int countNumbersWithUniqueDigits(int n) { if (n < 1) { return 1; } ... 阅读全文
posted @ 2016-06-15 16:42 blcblc 阅读(245) 评论(0) 推荐(0)

上一页 1 ··· 9 10 11 12 13 14 下一页