Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 25 下一页

2015年7月15日

摘要: Brutal-force solution is not hard to think about. But linear space input usually indicates O(n) DP solution.State design: dp[i]: total sum until index... 阅读全文
posted @ 2015-07-15 13:14 Tonix 阅读(393) 评论(0) 推荐(0)

摘要: An interview problem I encountered years ago.. 1ACclass Solution {public: void deleteNode(ListNode* node) { if(!node) return; Lis... 阅读全文
posted @ 2015-07-15 09:10 Tonix 阅读(143) 评论(0) 推荐(0)

2015年7月14日

摘要: My first thought made it unnecessarily difficult. Well, the correct solution falls into a typical pattern: use DP to calc cumulative results of each c... 阅读全文
posted @ 2015-07-14 05:02 Tonix 阅读(516) 评论(0) 推荐(0)

2015年7月11日

摘要: First please note, it is BST. So it is about value compare.class Solution {public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, Tree... 阅读全文
posted @ 2015-07-11 06:27 Tonix 阅读(195) 评论(0) 推荐(0)

2015年7月10日

摘要: A typical bucketing strategy, but it is probably the most complex one..Basically I refer tothissubmission. 阅读全文
posted @ 2015-07-10 13:16 Tonix 阅读(299) 评论(0) 推荐(0)

摘要: O(n) time O(n) space solution using stack:class Solution {public: bool isPalindrome(ListNode* head) { if (!head || !head->next) return t... 阅读全文
posted @ 2015-07-10 10:13 Tonix 阅读(136) 评论(0) 推荐(0)

2015年7月8日

摘要: Marked as mathematics problem, but if you are able to divide 1s into several cases, the AC code becomes natural.class Solution { unordered_map memo... 阅读全文
posted @ 2015-07-08 14:45 Tonix 阅读(193) 评论(0) 推荐(0)

2015年7月7日

摘要: First I was stuck at how to represent state of "add all except i".. but after checking editorial, it is simply inverted Coin Change problem..#include ... 阅读全文
posted @ 2015-07-07 05:38 Tonix 阅读(377) 评论(0) 推荐(0)

摘要: Very similar as "Implement Stack using Queues".class Queue { stack _s0; stack _s1; int _front; public: // Push element x to the back of... 阅读全文
posted @ 2015-07-07 04:45 Tonix 阅读(181) 评论(0) 推荐(0)

2015年7月6日

摘要: Just one line. Bit-wise ops:class Solution {public: bool isPowerOfTwo(int n) { return (n > 0) && (n & (n - 1)) == 0; }}; 阅读全文
posted @ 2015-07-06 07:35 Tonix 阅读(138) 评论(0) 推荐(0)

2015年7月3日

摘要: 1AC. 1D DP + Sieving#include #include #include #include #include #include #include #include #include #include #include using namespace std;int ways(in... 阅读全文
posted @ 2015-07-03 06:58 Tonix 阅读(210) 评论(0) 推荐(0)

2015年7月2日

摘要: Good one.. marked as DP, so I was striking to work out a DP formula... well, not all DP have a formula - one type of DP is called memorized search: th... 阅读全文
posted @ 2015-07-02 14:08 Tonix 阅读(830) 评论(0) 推荐(0)

摘要: Simply to utilize BST's property. The two-pass code below can be extended to support frequent insert\delete.struct SNode{ SNode(int rcnt) : cnt(rcn... 阅读全文
posted @ 2015-07-02 09:45 Tonix 阅读(150) 评论(0) 推荐(0)

2015年7月1日

摘要: First I thought it should be solved using DP, and I gave a standard O(n^2) solution:#include #include #include #include using namespace std;#define RE... 阅读全文
posted @ 2015-07-01 07:10 Tonix 阅读(327) 评论(0) 推荐(0)

2015年6月30日

摘要: 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 阅读(145) 评论(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 阅读(134) 评论(0) 推荐(0)

2015年6月29日

摘要: 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 阅读(136) 评论(0) 推荐(0)

2015年6月25日

摘要: 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 阅读(321) 评论(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 阅读(346) 评论(0) 推荐(0)

上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 25 下一页