Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

06 2015 档案

摘要:If coin order matters, that is, each sequence is unique, the DP function is simple enough to make it 1D DP. But key is that order DOESN'T matter, so w... 阅读全文
posted @ 2015-06-30 05:22 Tonix 阅读(467) 评论(0) 推荐(0)

摘要:class Solution {public: int romanToInt(string s) { std::unordered_map hm; hm['M'] = 1000; hm['D'] = 500; hm['C'] = ... 阅读全文
posted @ 2015-06-30 04:48 Tonix 阅读(146) 评论(0) 推荐(0)

摘要:char dict[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};class Solution { public: string pattern(int v, int level) { int offset = int(log10(l... 阅读全文
posted @ 2015-06-30 04:39 Tonix 阅读(136) 评论(0) 推荐(0)

摘要:Similar as "Majority Element". There are at most 2 such elements, for > floor(n/3), and every non-hit element will decrease count of EACH hit element.... 阅读全文
posted @ 2015-06-29 23:21 Tonix 阅读(137) 评论(0) 推荐(0)

摘要:The Editorial provides a Fast Fourier Transformation solution O(nlgn)... which is too maths for me. In the leaderboard, I found a not-that-fast O(n^2)... 阅读全文
posted @ 2015-06-25 14:14 Tonix 阅读(322) 评论(0) 推荐(0)

摘要:New techniques learnt: Trie can be used for some XOR problems. The basic idea: we build a MSB->LSB prefix Trie of all numbers; then query greedily: fi... 阅读全文
posted @ 2015-06-25 12:35 Tonix 阅读(347) 评论(0) 推荐(0)

摘要:Yes just an implementation problem.. a lot of typing work.#include #include #include #include #include #include #include #include #include #include us... 阅读全文
posted @ 2015-06-23 05:28 Tonix 阅读(302) 评论(0) 推荐(0)

摘要:Comparing with the 'I' one, there are two changes:1. if last operator is "+" or "-", we don't evaluate expression2. if last operator is "*" or "/", we... 阅读全文
posted @ 2015-06-22 12:14 Tonix 阅读(176) 评论(0) 推荐(0)

摘要:1st Try: brutal-force solution failed 3 test cases with TLE2nd Try: uint32_t bucketing - AC:#include #include #include #include #include #include #inc... 阅读全文
posted @ 2015-06-19 04:41 Tonix 阅读(309) 评论(0) 推荐(0)

摘要:This one is marked as "Advanced".. i don't tink so, not that hard if you can visualize all the bits from a to b. Two key points here:1. Say both a and... 阅读全文
posted @ 2015-06-18 10:03 Tonix 阅读(376) 评论(0) 推荐(0)

摘要:Two-queue solutionclass Stack { queue q; queue q0; int _top;public: // Push element x onto stack. void push(int x) { q.push(x); ... 阅读全文
posted @ 2015-06-16 04:35 Tonix 阅读(142) 评论(0) 推荐(0)

摘要:The answer byTuxdudeis perfect:http://stackoverflow.com/questions/11161465/existence-of-a-permutation-under-constraints-interview-street-manipulative-... 阅读全文
posted @ 2015-06-10 02:26 Tonix 阅读(292) 评论(0) 推荐(0)

摘要:My first try was DFS by intuition, but it ended up with MLE. So, the expected solution is to use stack:class Solution { struct Node { Nod... 阅读全文
posted @ 2015-06-09 13:41 Tonix 阅读(479) 评论(0) 推荐(0)

摘要:More on data structure.#include #include #include #include #include #include #include #include using namespace std;typedef pair Point;struct DistComp{... 阅读全文
posted @ 2015-06-09 09:34 Tonix 阅读(258) 评论(0) 推荐(0)

摘要:Classic and challenging DP! And you need combine several tricks together with DP to make it 100% pass.My main reference is here:https://github.com/hav... 阅读全文
posted @ 2015-06-09 05:10 Tonix 阅读(1219) 评论(0) 推荐(0)

摘要:DFS solution is intuitive. I put my BFS solution below:class Solution {public: int countNodes(TreeNode* root) { if (!root) return 0; ... 阅读全文
posted @ 2015-06-06 05:35 Tonix 阅读(306) 评论(0) 推荐(0)

摘要:Lesson learnt: std::multiset is a heap structure supporting random removal...class Solution { public: bool containsNearbyAlmostDuplicate(vec... 阅读全文
posted @ 2015-06-05 07:41 Tonix 阅读(153) 评论(0) 推荐(0)

摘要:Not hard, but with some amount of coding. Brutal-force would work: iterate each unique pair of points. And I used "y=ax+b" to check each point which s... 阅读全文
posted @ 2015-06-05 03:50 Tonix 阅读(224) 评论(0) 推荐(0)

摘要:import reimport ioimport sysinput_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')s = input_stream.readlines()s = "\n".join(s)pc = '(//.*... 阅读全文
posted @ 2015-06-03 07:34 Tonix 阅读(623) 评论(0) 推荐(0)

摘要:So fun! It connects algorithm(regex) with real world usages!So basically speaking, C:pointer syntax, #include\scanf\typedef; Java: import\public class... 阅读全文
posted @ 2015-06-03 07:09 Tonix 阅读(737) 评论(0) 推荐(0)

摘要:Really fun regex one.import ren = int(input())txt = ''for _ in range(n): str = input() txt = txt + strdict = {}all = re.findall(']*>', txt)for i... 阅读全文
posted @ 2015-06-03 02:13 Tonix 阅读(184) 评论(0) 推荐(0)

摘要:A relatively more complex regex problem to work on. It is fun!import ren = input()for _ in range(n): str = raw_input() pl = '[+-]?([1-8]?[0-9]([... 阅读全文
posted @ 2015-06-01 13:57 Tonix 阅读(506) 评论(0) 推荐(0)

摘要:Pretty classic greedy problem to work on. Here is how to approach it:1. "the smallest team is as large as possible." actually means, team members shou... 阅读全文
posted @ 2015-06-01 11:13 Tonix 阅读(268) 评论(0) 推荐(0)

摘要:My intuition told me that it is a line-scan process.. and yes it is. First, we sort all (a,b,k) by index\start-end, then we do a line scan. And in C++... 阅读全文
posted @ 2015-06-01 09:57 Tonix 阅读(435) 评论(0) 推荐(0)

摘要:Note this smart observation from Editorial: "M will be either P or Q or (A_i+A_j)/2"..Yea I know, my code is not condense enough..#include #include #i... 阅读全文
posted @ 2015-06-01 08:27 Tonix 阅读(248) 评论(0) 推荐(0)