Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  502 随笔 :: 0 文章 :: 3 评论 :: 11万 阅读
< 2025年6月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 1 2 3 4 5
6 7 8 9 10 11 12

05 2015 档案

摘要:Maintain a hashset with size of (K + 1)class Solution {public: bool containsNearbyDuplicate(vector& nums, int k) { unordered_set hs; ... 阅读全文
posted @ 2015-05-30 01:36 Tonix 阅读(157) 评论(0) 推荐(0)

摘要:Good one. My first reaction to this problem is the same idea as this answer:https://leetcode.com/discuss/37365/accepted-c-solution-o-nlogn-using-maxhe... 阅读全文
posted @ 2015-05-29 01:44 Tonix 阅读(393) 评论(0) 推荐(0)

摘要:I guess the punch line of this one is Sieving for primes.#include #include #include #include #include #include #include #include using namespace std;v... 阅读全文
posted @ 2015-05-28 01:48 Tonix 阅读(260) 评论(0) 推荐(0)

摘要:Apparently it is by a backwards derivation solution. Say energy at h[i] is e, the next energy at h[i+1] is 2*e - h[i+1] => e', so backwards, e = ceil(... 阅读全文
posted @ 2015-05-27 07:03 Tonix 阅读(261) 评论(0) 推荐(0)

摘要:We match larger in array_a with smaller in array_b, by which we can have as even sum as possible, so we don't have too small sums.#include #include #i... 阅读全文
posted @ 2015-05-27 00:44 Tonix 阅读(139) 评论(0) 推荐(0)

摘要:Apparently, more expensive flowers should be bought with lower coeff. (Greedy part), and any unbalanced assignment would cause extra cost.So the code ... 阅读全文
posted @ 2015-05-26 14:16 Tonix 阅读(151) 评论(0) 推荐(0)

摘要:Typical recursion usage.class Solution { vector> ret; void dfs(vector curr, int currSum, int maxN, int n, int k) { // Ending ... 阅读全文
posted @ 2015-05-25 15:14 Tonix 阅读(233) 评论(0) 推荐(0)

摘要:To have "shortest" expanded palindrome, we should know the longest "heading" palindrome in original string, so that we can reuse as much part as possi... 阅读全文
posted @ 2015-05-23 02:17 Tonix 阅读(249) 评论(0) 推荐(0)

摘要:It is modulo version of "max sum of contiguous subarray". So similar pattern can be applied too, but with tricks regarding to modulo ops.I checked edi... 阅读全文
posted @ 2015-05-22 14:19 Tonix 阅读(653) 评论(0) 推荐(0)

摘要:Good one to learn Binary Indexed Tree (Fenwick Tree). Simply grabbed the editorial's code but with comments.#include #include #include #include #inclu... 阅读全文
posted @ 2015-05-21 07:34 Tonix 阅读(276) 评论(0) 推荐(0)

摘要:A high quality DP problem to work on. It is not an merely educational DP, it is subtle.Basic ideas: 1. Run original DP twice, 1st with num[0] selecte... 阅读全文
posted @ 2015-05-20 11:00 Tonix 阅读(439) 评论(0) 推荐(0)

摘要:Trie, again.class TrieNode {public: // Initialize your data structure here. TrieNode() : prev(nullptr), c(0), bIsLast(false) { } TrieNo... 阅读全文
posted @ 2015-05-20 04:32 Tonix 阅读(192) 评论(0) 推荐(0)

摘要:I'm glad to see that LeetCode has finally realized the importance of Trie.My C++ code can be further optimized..class TrieNode {public: // Initiali... 阅读全文
posted @ 2015-05-20 01:28 Tonix 阅读(262) 评论(0) 推荐(0)

摘要:An ACM-level problem because it involves "advanced maths". It should not be marked as "Moderate". Other than that, it is a medium level DP one.*Math m... 阅读全文
posted @ 2015-05-19 10:53 Tonix 阅读(268) 评论(0) 推荐(0)

摘要:This is my 1st 3D DP problem, and it should be an educational one. But, still tricky to me.Here is a good article:http://www.cnblogs.com/sunshineatnoo... 阅读全文
posted @ 2015-05-15 15:49 Tonix 阅读(253) 评论(0) 推荐(0)

摘要:Basically speaking, I got higher resolution view into code now, in a 庖丁解牛 style. Previously, I treated one program as a whole, and sometimes I got con... 阅读全文
posted @ 2015-05-15 03:28 Tonix 阅读(111) 评论(0) 推荐(0)

摘要:This one lets you print out one topological sorted sequence. Either BFS or DFS works. But there are tricky details.This is my reference:https://leetco... 阅读全文
posted @ 2015-05-15 02:46 Tonix 阅读(217) 评论(0) 推荐(0)

摘要:O(n): Sliding window:class Solution {public: int minSubArrayLen(int s, vector& nums) { int len = nums.size(); if (len == 0) return... 阅读全文
posted @ 2015-05-13 15:43 Tonix 阅读(229) 评论(0) 推荐(0)

摘要:Topological sorting. This is my DFS solution. Please note that I used _rec to avoid duplicate checking.class Solution {public: map rec; set _rec... 阅读全文
posted @ 2015-05-13 14:37 Tonix 阅读(148) 评论(0) 推荐(0)

摘要:Implementation problem.class TrieNode {public: // Initialize your data structure here. TrieNode() { c = 0; bIsLast = false; } ... 阅读全文
posted @ 2015-05-13 13:28 Tonix 阅读(266) 评论(0) 推荐(0)

摘要:Solution 1:https://www.hackerrank.com/challenges/number-list/editorialReversed thought: total no. of subsets - no. of subsets without arr[i] > kSoluti... 阅读全文
posted @ 2015-05-11 05:08 Tonix 阅读(185) 评论(0) 推荐(0)

摘要:I treated it too difficult.. nothing special, just some optimization mentioned as:http://saraguru.weebly.com/how-i-solved/find-maximum-index-product-h... 阅读全文
posted @ 2015-05-10 14:12 Tonix 阅读(439) 评论(0) 推荐(0)

摘要:It requires O(nlgn) solution. And actually I think the passing code is for "non-decreasing"..#include #include #include #include #include #include #in... 阅读全文
posted @ 2015-05-10 12:30 Tonix 阅读(219) 评论(0) 推荐(0)

摘要:Really interesting problem. Naive solution would be O(n^3). But please note the pattern here: (i, j, k) -> (i + 1, j + 1, k) -> (i + 2, j + 2, k)... t... 阅读全文
posted @ 2015-05-08 07:23 Tonix 阅读(465) 评论(0) 推荐(0)

点击右上角即可分享
微信分享提示