Tony's Log

Algorithms, Distributed System, Machine Learning

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

2015年9月11日

摘要: One-pass Greedy solution. So beautiful.class Solution {public: void wiggleSort(vector& nums) { for(int i = 1; i nums[i]) ... 阅读全文
posted @ 2015-09-11 02:08 Tonix 阅读(239) 评论(0) 推荐(0)

摘要: Lesson learnt: Get rid of XX algorithm routines clogging your mind and focus\enjoy the problem itself!// Forward declaration of the knows API.bool kno... 阅读全文
posted @ 2015-09-11 00:48 Tonix 阅读(127) 评论(0) 推荐(0)

2015年9月4日

摘要: sum[i..j] = sum[0..j] - sum[0..i-1]. We use a hashmap to check a previous matching index with a given number.class Solution {public: vector subarra... 阅读全文
posted @ 2015-09-04 06:02 Tonix 阅读(176) 评论(0) 推荐(0)

摘要: Sorting is a natural solution. But, you don't have to run O(nlgn) sorting for all the time. Counting sort is O(n)!class Solution {public: int hInde... 阅读全文
posted @ 2015-09-04 04:58 Tonix 阅读(179) 评论(0) 推荐(0)

2015年9月2日

摘要: I made it too complicated first.. It is really simply if full-tree in-order traversal is allowed.class Solution { int inx, sofar; // closest boo... 阅读全文
posted @ 2015-09-02 11:24 Tonix 阅读(256) 评论(0) 推荐(0)

2015年9月1日

摘要: Just take care of corner cases.vector sec3 = { "", "Thousand", "Million", "Billion" };vector sig = { "", "One", "Two", "Three", "Four", "Five", "Six",... 阅读全文
posted @ 2015-09-01 13:45 Tonix 阅读(158) 评论(0) 推荐(0)

2015年8月29日

摘要: One pass in-place solution: all swaps.class Solution {public: /** * @param nums: a vector of integers * @return: nothing */ void partit... 阅读全文
posted @ 2015-08-29 14:38 Tonix 阅读(206) 评论(0) 推荐(0)

摘要: A variation to a classical DP: LCS.class Solution {public: /** * @param A an integer array * @return A list of integers includes the index o... 阅读全文
posted @ 2015-08-29 11:43 Tonix 阅读(208) 评论(0) 推荐(0)

摘要: It can be solved based on the code from "Strobogrammatic Number II". The idea is pretty straight forward - binary search the boundaries.class Solution... 阅读全文
posted @ 2015-08-29 06:59 Tonix 阅读(173) 评论(0) 推荐(0)

摘要: This is abouthttps://en.wikipedia.org/wiki/Run-length_encoding. The trick is, for a valid char, we only compress up to 254 occurences - count 255 mean... 阅读全文
posted @ 2015-08-29 01:34 Tonix 阅读(317) 评论(0) 推荐(0)

2015年8月25日

摘要: Key: each of 2\3\5 is trying to multiply with the least number it has not been multiplied.class Solution {public: int nthUglyNumber(int n) { ... 阅读全文
posted @ 2015-08-25 13:15 Tonix 阅读(125) 评论(0) 推荐(0)

摘要: Another topological sorting problem. Note: the DFS one is like a 'post-order' traversal.class Solution { unordered_map> g; unordered_set visited... 阅读全文
posted @ 2015-08-25 12:44 Tonix 阅读(242) 评论(0) 推荐(0)

2015年8月24日

摘要: A variation of 3Sum. And the trick is, (i& nums, int target) { size_t len = nums.size(); if(len = target) k--; ... 阅读全文
posted @ 2015-08-24 14:38 Tonix 阅读(152) 评论(0) 推荐(0)

摘要: Use constructive strategy: we compose each of the 26 variations of one word.class Solution {public: vector> groupStrings(vector& strings) { ... 阅读全文
posted @ 2015-08-24 12:26 Tonix 阅读(220) 评论(0) 推荐(0)

摘要: I learnt a clean idea: all read is from the 4-char buffer.int read4(char *buf);class Solution { int offset; int validLen; char _buf[4]; ... 阅读全文
posted @ 2015-08-24 11:42 Tonix 阅读(159) 评论(0) 推荐(0)

2015年8月23日

摘要: An interesting DFS with a lot of details to take care of.class Solution { vector> ret; void go(int n, vector sofar, int minF) { int st... 阅读全文
posted @ 2015-08-23 12:43 Tonix 阅读(260) 评论(0) 推荐(0)

摘要: Classic DP! For house[i] to pick a min-color from dp[i-1], we only need to check if color j is the min cost color index of dp[i - 1]; if yes, then we ... 阅读全文
posted @ 2015-08-23 12:21 Tonix 阅读(235) 评论(0) 推荐(0)

2015年8月22日

摘要: Simply store indices in ctor.class WordDistance { unordered_map> hm;public: WordDistance(vector& words) { for (int i = 0; i &vec1 = hm[w... 阅读全文
posted @ 2015-08-22 11:18 Tonix 阅读(179) 评论(0) 推荐(0)

摘要: Just take care of corner cases..class Vector2D { vector> &r; int i, i0;public: Vector2D(vector>& vec2d) : r(vec2d), i(0), i0(0) { i... 阅读全文
posted @ 2015-08-22 10:59 Tonix 阅读(182) 评论(0) 推荐(0)

摘要: Linear scan after sorting. Please note sorting detail.typedef std::pair Rec;class Solution {public: int minMeetingRooms(vector& intervals) { ... 阅读全文
posted @ 2015-08-22 10:37 Tonix 阅读(184) 评论(0) 推荐(0)

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