自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(176)
  • 资源 (8)
  • 收藏
  • 关注

原创 Sliding Window Maximum

使用deque存数组的索引值,保证deque中元素是降序的,即每次取front就能取到最大元素。class Solution {public:    vector maxSlidingWindow(vector& nums, int k) {        deque win;        vector res;                if(nums.

2015-08-15 11:15:52 425

原创 QuickSort 和 QuickSelection中partition注记

CTCI 5th中提到了quicksort partition中的另一种写法,感觉比算法导论上的更容易理解,更直观。其中需要注意的是:1) while(A[left] 2) pivot的选取,可以选取[start, end]中任何一个,或者随机选取。3) return left-1,是partition的左半部分的最有一个元素的Index。Quick Partition

2014-11-28 23:17:55 571

原创 任意进制的转换(base2-base36)

思路和普通的十进制转任意进制相同,假设将M进制转N进制,

2014-11-21 10:54:50 3793

转载 autocomplete

1. using Trie with each node attached a list of suggestions.2. using

2014-11-10 21:13:17 431

转载 bit operations topics

source1: Low Level Bit Hacks You Absolutely Must Know

2014-10-30 20:15:41 420

原创 Largest Subtree Which is a Binary Search Tree (BST)

找到一个树中最大的BST subtree,题目来源:http://leetcode.com/2010/11/largest-binary-search-tree-bst-in.html代码

2014-10-30 10:54:39 436

原创 Coins in a Line

题目来源: http://leetcode.com/2011/02/coins-in-line.html二维DP。代码如下:

2014-10-29 21:29:56 402

原创 restore BST from pre-order

#include #include #include using namespace std;struct TreeNode{ int val; TreeNode *left; TreeNode *right; TreeNode(int v): val(v){}};TreeNode *restore(int min, int max, int &idx, vector a

2014-10-28 22:17:50 405

原创 find the N-th node In Inorder

1. Write a function that returns a node in a tree given two parameters: pointer to the root node and the in order traversal number of the node we want to return. The only information stored in the

2014-10-21 15:38:09 395

原创 Find K-th smallest in N sorted arrays

Divide and Conquer, 每次将问题规模缩小

2014-10-20 21:33:08 474

原创 String two pointer swapping (合集)

相关问题:1. Minimum Window Substring

2014-10-20 15:28:32 420

原创 Rotated Sorted Array(合辑)

Corner cases: 1 duplicate elements.  2. the array is not rotated at all.1. Find

2014-10-20 09:56:41 448

原创 Count index of sequence of words

problem source: http://www.careercup.com/question?id=21117662

2014-10-19 11:37:28 452

转载 (MS)Design an algorithm to find the maximum subsquare such that all four borders are filled with bla

Imagine there is a square matrix with n x n cells. Each cell is either filled with a black pixel or a white pixel. Design an algorithm to find the maximum Subsquare such that all four borders are fill

2014-10-19 10:02:58 543

原创 整数相加溢出判断

判断两个数相加overflow的代码:int add(int a, int b){ if(((a>>31) & 1) == 0 && ((b>>31) & 1) == 0) { if(a <= INT_MAX-b) return a+b; else return 88888; }

2014-10-18 16:50:53 563

原创 lower_bound和upper_bound的另一种写法

int lower_bound(int A[], int n, int target) { int left = 0, right = n-1; while(left <= right) { int mid = left+(right-left)/2; if(A[mid] < target)

2014-10-15 10:24:11 510

原创 longest substring with two unique charachters

O(n)双指针。code#include #include #include #include #include using namespace std;string longest(string str){ int longest = 0; int longest_start = -1; int occurance[256]; int count = 0

2014-10-14 18:27:46 430

原创 Point inside Triangle/Rectangle Problem

1. 面积法,检查所有边和point围城

2014-10-14 16:35:48 684

原创 计算三角形的面积

给出三个点计算三角形的面积。

2014-10-14 16:29:50 688

原创 count duplicate in a sorted array

count insead of find. binary search.#include #include using namespace std;map blist; void count_dup(int* arr, int start, int end){ if(end == start) { blist[arr[start]] +=1;

2014-10-14 12:02:11 499

原创 CTRL+A, CTRL+C, CTRL+V

来源 http://leetcode.com/2011/01/ctrla-ctrlc-ctrlv.html原题的思路不好理解,可以考虑使用冬天

2014-10-13 21:58:49 1198

转载 24点问题算法

DFS

2014-10-13 11:03:07 716

原创 Copy Binary Tree with Random Pointer

similar with the leetcode problem: copy LinkedList with random pointer

2014-10-12 19:35:16 565

转载 求分数的循环节和小数表示

参考http://www.cnblogs.com/clive/archive/2009/10/28/Circular_decimal_fraction_USCAO_2_4_5.html

2014-10-12 15:30:00 1663

转载 uva 10716 - Minimum Swap to form Palindrome

转自: http://blog.csdn.net/chenguolinblog/article/details/7908609

2014-10-07 22:03:33 460

转载 Lowest Common Ancestor

1. 如果只有一次查询,参考

2014-10-07 19:51:52 460

原创 Leetcode第三刷需要注意的问题

2. Reverse Words in a String注意最后一个单词后面的空格。4. Max Points on a Line 注意slope为double类型, infinity是slope的一个特殊值。5. Sort List:需要注意fast slow pointer在只有两个节点时是否能够将list分成两部分。6. Insertion

2014-09-30 08:31:22 565

转载 Max Points on a Line

class Solution {public: int maxPoints(vector &points) { if(points.size() <= 2) return points.size(); int maxpoint = 0; unordered_map hash; f

2014-09-29 16:11:31 343

转载 Maximum Product Subarray

source: http://blog.csdn.net/sbitswc/article/details/39546719

2014-09-29 15:06:28 353

原创 suffix tree pattern matching

// A simple C++ implementation of substring search using trie of suffixes#include #include #define MAX_CHAR 256using namespace std;// A Suffix Trie (A Trie of all suffixes) Nodeclass SuffixTrie

2014-09-28 16:14:18 506

原创 Interview Set

1. You have an array of n elements, and a sum. Check if any 2 elements in the array sum to the given sum. ( Expected time complexity O(n). Use hashing)

2014-09-13 12:08:41 415

转载 Max Sum in circularly situated Values

Max Sum in circularly situated ValuesThis question was asked first in FACEBOOK On Campus for Internship.There are N trees in a circle. Each tree has a fruit value associated with it.  A

2014-09-13 11:53:03 584

原创 Finding all possible simple paths (paths without cycles) between two vertices in a graph

This problem is different from traditional BFS or DFS search, as the previously visited node can be visited again, as they are on different paths.M

2014-09-12 20:28:33 553

转载 Graph Traversal (BFS vs DFS vs Stack)

BFS template: (from wiki)1 procedure BFS(G,v) is2 create a queue Q3 create a set V4 add v to V5 enqueue v onto Q6 while Q is not empty loop7 t ← Q.dequeue()

2014-09-11 15:56:18 779

原创 Text Justification

注意最后一行和只有一个word的行的特殊处理。class Solution {public: vector fullJustify(vector &words, int L) { vector result; if(words.size() == 0) return result; int start = 0;

2014-09-11 11:36:18 310

原创 Divide Two Integers

每次除数增倍,知道

2014-09-10 21:01:31 327

原创 Spiral Matrix

注意细节。class Solution {public: vector spiralOrder(vector > &matrix) { vector result; int row = matrix.size(); if(row == 0) return result; int col = matrix

2014-09-10 20:22:49 312

原创 Substring with Concatenation of All Words

check each possible position i to see if the substring start at position i is a

2014-09-10 18:01:19 328

原创 Palindrome Number

和Reverse Integer类似,按位处理,而不要转换成String。

2014-09-10 12:08:11 316

原创 Reverse Integer

注意处理overflow和negative的问题。class Solution {public: int reverse(int x) { bool positive = (x>=0); x = abs(x); int result = 0; for(; x; x/=10)

2014-09-10 11:54:03 299

Data-Intensive Text Processing with MapReduce

Data-Intensive Text Processing with MapReduce是目前较好地专门介绍Hadoop MapReduce程序算法设计的书籍

2012-03-09

Mahout in Action

Mahout是Apache旗下的开源项目,利用hadoop进行机器学习和数据挖掘

2012-03-09

hadoop官方指南(第二版,英文版)

hadoop主要参与者编写的官方指南,学习hadoop的首选推荐

2011-12-21

Boost C++参考

堪称经典的国外Boost C++库教程,在未来的发展中,Boost C++有望成为标准C++库的一部分。

2009-09-21

KDE 2 Qt Programming Bible

基于Qt的KDE开发经典之作,英文原版的

2009-03-14

基于Qt的C++设计模式

基于Qt的C++设计模式,可作为研究Qt源码之用

2009-03-14

The Definitive Guide to SWT and JFace

国外权威的SWT/JFace教程

2008-02-22

GPU编程指导

国外权威的显卡编程资料

2008-02-12

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除