Tony's Log

Algorithms, Distributed System, Machine Learning

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

2015年10月1日

摘要: Typical Trie usage. But please note that it could be any order of input strings.#include #include #include #include #include #include #include using n... 阅读全文
posted @ 2015-10-01 01:07 Tonix 阅读(353) 评论(0) 推荐(0)

2015年9月30日

摘要: Like "Best Time to Buy Stock III" with "Longest continuous subarray"class Solution {public: /** * @param nums: A list of integers * @return... 阅读全文
posted @ 2015-09-30 14:41 Tonix 阅读(174) 评论(0) 推荐(0)

摘要: Here is a BFS solution which is compatible with LeetCode binary tree format.class Solution {public: /** * This method will be invoked first, yo... 阅读全文
posted @ 2015-09-30 13:45 Tonix 阅读(178) 评论(0) 推荐(0)

2015年9月29日

摘要: Catch the sparkle: if only one number is duplicated in [1..n], all following numbers will be "shifted" right.class Solution {public: int findDuplic... 阅读全文
posted @ 2015-09-29 23:51 Tonix 阅读(135) 评论(0) 推荐(0)

2015年9月24日

摘要: DFS ended up with TLE. Only BFS works./** * Definition for Directed graph. * struct DirectedGraphNode { * int label; * vector neighbors; * ... 阅读全文
posted @ 2015-09-24 05:14 Tonix 阅读(246) 评论(0) 推荐(0)

2015年9月23日

摘要: Simply a revise of a genius Greedy algorithm seen on LeetCode - linear walking.class Solution {public: /** * @param matrix: A list of lists of ... 阅读全文
posted @ 2015-09-23 05:19 Tonix 阅读(134) 评论(0) 推荐(0)

摘要: Naive solution is O(n^4). But on 1 certain dimension, naive O(n^2) can be O(n) by this well-known equation: sum[i..j] = sum[0..j] - sum[0..i]. And pls... 阅读全文
posted @ 2015-09-23 04:34 Tonix 阅读(231) 评论(0) 推荐(0)

2015年9月22日

摘要: A typical swapping.class Solution {public: /** * @param chars: The letters array you should sort. */ bool isUpper(char c) { r... 阅读全文
posted @ 2015-09-22 13:35 Tonix 阅读(132) 评论(0) 推荐(0)

2015年9月21日

摘要: class PeekingIterator : public Iterator { bool bPeeked; int val;public: PeekingIterator(const vector& nums) : Iterator(nums) { val = -... 阅读全文
posted @ 2015-09-21 15:27 Tonix 阅读(138) 评论(0) 推荐(0)

2015年9月20日

摘要: A variation to Sort Colors I - we take care of 2 sides, recursively\iteratively.class Solution{public: /** * @param colors: A list of integer ... 阅读全文
posted @ 2015-09-20 15:48 Tonix 阅读(152) 评论(0) 推荐(0)

摘要: class Solution {public: void moveZeroes(vector& nums) { size_t n = nums.size(); if(n < 2) return; int i = 0, j = 0; ... 阅读全文
posted @ 2015-09-20 04:31 Tonix 阅读(102) 评论(0) 推荐(0)

2015年9月18日

摘要: class Solution {public: /** *@param n, m: Two integer *@param i, j: Two bit positions *return: An integer */ int updateBits(int ... 阅读全文
posted @ 2015-09-18 14:02 Tonix 阅读(170) 评论(0) 推荐(0)

摘要: O(nlgn) with repeated numbers.. Please note the extra repeat count array:class Solution {public: /** * @param nums: The integer array * @re... 阅读全文
posted @ 2015-09-18 03:12 Tonix 阅读(143) 评论(0) 推荐(0)

2015年9月15日

摘要: A simple variation to 0-1 Knapsack.class Solution {public: /** * @param m: An integer m denotes the size of a backpack * @param A: Given n it... 阅读全文
posted @ 2015-09-15 10:47 Tonix 阅读(130) 评论(0) 推荐(0)

摘要: Partial Sort.class Solution {public: /** * @param nums: A list of integers. * @return: An integer denotes the middle number of the array. ... 阅读全文
posted @ 2015-09-15 05:24 Tonix 阅读(210) 评论(0) 推荐(0)

摘要: Capable to k-vector input too:class ZigzagIterator { int x; int i; int max_x; vector*> l; void moveon() { int oldi= i... 阅读全文
posted @ 2015-09-15 03:55 Tonix 阅读(153) 评论(0) 推荐(0)

2015年9月13日

摘要: A variation to Binary Tree iteration.class Solution { bool isSame(TreeNode *p1, TreeNode *p2) { if (!p1 && !p2) return true; if( (... 阅读全文
posted @ 2015-09-13 14:07 Tonix 阅读(198) 评论(0) 推荐(0)

摘要: Typical solution: convert it to Maximum Array problem.And here is my solution: O(n) by using Greedy strategy on this equation: sum[i..j] = sum[0..j] -... 阅读全文
posted @ 2015-09-13 13:47 Tonix 阅读(181) 评论(0) 推荐(0)

摘要: Using XOR on bits.class Solution {public: /* * @param a: The first integer * @param b: The second integer * @return: The sum of a and b... 阅读全文
posted @ 2015-09-13 13:00 Tonix 阅读(159) 评论(0) 推荐(0)

2015年9月12日

摘要: An intuitive DP.class Solution {public: int numSquares(int n) { vector dp(n + 1, INT_MAX); dp[0] = 0; for(int i = 0; i... 阅读全文
posted @ 2015-09-12 08:43 Tonix 阅读(141) 评论(0) 推荐(0)

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