Tony's Log

Algorithms, Distributed System, Machine Learning

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

2015年8月22日

摘要: A typical DPclass Solution {public: int minCost(vector>& costs) { size_t len = costs.size(); if(len == 0) return 0; ve... 阅读全文
posted @ 2015-08-22 00:46 Tonix 阅读(179) 评论(0) 推荐(0)

2015年8月21日

摘要: A typical sliding window solution.class Solution { int rec[26]; // for a-z int rec1[26]; // for A-Z int cnt; int &getCnt(char c) ... 阅读全文
posted @ 2015-08-21 13:16 Tonix 阅读(126) 评论(0) 推荐(0)

摘要: DFS to check cyclic. Please note some details.class Solution{ unordered_map> g; unordered_set visited; bool go(int i, int p) // true - cy... 阅读全文
posted @ 2015-08-21 12:41 Tonix 阅读(263) 评论(0) 推荐(0)

2015年8月20日

摘要: A variation of linear scan..typedef pair Rec;class Solution {public: int shortestDistance(vector& words, string word1, string word2) { v... 阅读全文
posted @ 2015-08-20 15:32 Tonix 阅读(136) 评论(0) 推荐(0)

摘要: A typical recursion one.class Solution { bool _verify(vector &in, int i, int j, int low, int high) { if (i > j) return tr... 阅读全文
posted @ 2015-08-20 14:59 Tonix 阅读(249) 评论(0) 推荐(0)

摘要: Recursion, a natural thought:class Solution { // Top : BottomRight std::pair rotate(TreeNode *p) { if (!p->left && !p->right) ... 阅读全文
posted @ 2015-08-20 13:23 Tonix 阅读(172) 评论(0) 推荐(0)

2015年8月10日

摘要: It should be categorized as 'Advanced' I think ... Anyway, Fenwick tree is the key.Editorial:https://www.hackerrank.com/challenges/candles-2/editorial... 阅读全文
posted @ 2015-08-10 13:07 Tonix 阅读(666) 评论(0) 推荐(0)

2015年8月3日

摘要: A trickier Dijkstra.#include #include #include #include #include #include #include #include #include using namespace std;const int INF = std::numeric_... 阅读全文
posted @ 2015-08-03 07:41 Tonix 阅读(399) 评论(0) 推荐(0)

摘要: Typical Floyd-Walshall Algorithm.#include #include #include #include #include #include #include #include #include using namespace std;const long DIST_... 阅读全文
posted @ 2015-08-03 01:52 Tonix 阅读(337) 评论(0) 推荐(0)

2015年8月2日

摘要: No big difference with "Breadth First Search: Shortest Reach", but this statement is crucial:If there are edges between the same pair of nodes with di... 阅读全文
posted @ 2015-08-02 15:18 Tonix 阅读(1179) 评论(0) 推荐(0)

摘要: Typical Dijstra algorithm impl. one.#include #include #include #include #include #include #include #include #include using namespace std;const long DI... 阅读全文
posted @ 2015-08-02 14:43 Tonix 阅读(1196) 评论(0) 推荐(0)

摘要: A combination of different DP passes.https://www.hackerrank.com/challenges/lego-blocks/editorial#include #include #include using namespace std;typedef... 阅读全文
posted @ 2015-08-02 05:31 Tonix 阅读(869) 评论(0) 推荐(0)

2015年8月1日

摘要: My initial thought was recursive (a op b) evaluation, which doesn't work quite well.The correct way is to split by op. And, we can cache calculaton re... 阅读全文
posted @ 2015-08-01 13:45 Tonix 阅读(150) 评论(0) 推荐(0)

2015年7月23日

摘要: A trickier binary search one.//////////////class Solution { int lower_bound_vert(vector>& m, int col, int i, int j, int target) { int... 阅读全文
posted @ 2015-07-23 15:06 Tonix 阅读(178) 评论(0) 推荐(0)

2015年7月21日

摘要: Classic.. just classic. It is a mix of Greedy and DP. The naive DP is, iterate over all [1..Bi] which is O(n^3). However, deeper thought into the prob... 阅读全文
posted @ 2015-07-21 15:40 Tonix 阅读(694) 评论(0) 推荐(0)

摘要: Intuition: 2D DP. Basic idea: compose square at dp[i][j] from dp[i-1][j-1]. You need 2 facility 2D matrix: accumulated horizontal\vertical number of 1... 阅读全文
posted @ 2015-07-21 13:18 Tonix 阅读(171) 评论(0) 推荐(0)

2015年7月20日

摘要: Interesting one.. It is more about data structure design actually. After you figure out how to represent cells, the DP formula will be very intuitive ... 阅读全文
posted @ 2015-07-20 12:15 Tonix 阅读(356) 评论(0) 推荐(0)

摘要: Monotonic Queue is getting more popular, and finally LeetCode put it on.Typical Solution: element in array will be pushed\popped in\from a sorted data... 阅读全文
posted @ 2015-07-20 11:08 Tonix 阅读(438) 评论(0) 推荐(0)

2015年7月17日

摘要: Actually I think it should belong to category of 'Bits Manipulation'.. but still, a really good one.My first reaction was, how to derive from a ^ (b #... 阅读全文
posted @ 2015-07-17 14:17 Tonix 阅读(357) 评论(0) 推荐(0)

2015年7月16日

摘要: Question 1: without division. We can simply compose left\right accumulated product arrays:typedef long long LL;class Solution {public: vector produ... 阅读全文
posted @ 2015-07-16 13:21 Tonix 阅读(190) 评论(0) 推荐(0)

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