*博客头图：

RGB颜色，例如：#AFAFAF

Hover：

RGB颜色，例如：#AFAFAF

RGB颜色，例如：#AFAFAF

# 孙佰贵的专栏

• 博客(100)
• 资源 (28)

#### 原创 [LeetCode]Reverse Nodes in k-Group

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {//once the link order of the list is changed, //we must keep the previous pointer(p in the c

2013-05-31 10:40:02 1492

#### 原创 [LeetCode]Reverse Integer

class Solution {public: int reverse(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function int sign = 1; if(x < 0) sign = -1; unsigned int num = x < 0 ? -x

2013-05-31 10:39:53 691

#### 原创 [LeetCode]Remove Nth Node From End of List

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { // Start typing your

2013-05-31 10:39:34 1227

#### 原创 [LeetCode]Remove Element

class Solution {public: int removeElement(int A[], int n, int elem) { // Start typing your C/C++ solution below // DO NOT write int main() function int len = 0; for (int i = 0; i < n; ++i)

2013-05-31 10:39:31 1398 2

#### 原创 [LeetCode]Remove Duplicates from Sorted List II

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {//three pointer, the previous valid pointer, the first pointer of these same elements, curre

2013-05-31 10:39:27 1203

#### 原创 [LeetCode]Remove Duplicates from Sorted List

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {//just record the previous pointer, and the current pointerpublic: ListNode *deleteDuplica

2013-05-31 10:39:24 1061

#### 原创 [LeetCode]Remove Duplicates from Sorted Array II

class Solution {//get the condition of copy or not copypublic: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int cur = 2

2013-05-31 10:39:20 2125

#### 原创 [LeetCode]Remove Duplicates from Sorted Array

class Solution {public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(0 == n) return 0; int len = 1; for (int i =

2013-05-31 10:39:17 750

#### 原创 [LeetCode]Regular Expression Matching

class Solution {//1. If the next character of p is NOT '*', then it must match the current character of s. //Continue pattern matching with the next character of both s and p.//2. If the next chara

2013-05-31 10:39:13 2296

#### 原创 [LeetCode]Recover Binary Search Tree

struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {//the clue is that if we traverse the tree in inorder, then it

2013-05-31 10:39:09 2188

#### 原创 [LeetCode]Pow(x, n)

class Solution {//divide-and-conquer//classicpublic: double pow(double x, int n) { if (n == 0) return 1.0; // Compute x^{n/2} and store the result into a temporary // variable to avoid unnec

2013-05-31 10:39:05 1899

#### 原创 [LeetCode]Populating Next Right Pointers in Each Node

2013-05-31 10:39:02 1160

#### 原创 [LeetCode]Plus One

class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function vector ans; int len = digits.size(); int carry = 1;

2013-05-31 10:38:58 1943

#### 原创 [LeetCode]Permutations II

class Solution {//DFS//always let the next same element go first, //in such a case we can cut down half same permutations //generated by these same element//need more practicepublic: vector > p

2013-05-31 10:38:54 2389

#### 原创 [LeetCode]Permutations

class Solution {//DFSpublic: vector > permute(vector &num) { // Start typing your C/C++ solution below // DO NOT write int main() function int n = num.size(); if(0 == n) return vector >();

2013-05-31 10:38:50 1380

#### 原创 [LeetCode]Permutation Sequence

class Solution {//decompose the big problem into smaller problemprivate: vector numT;//keep record of number state, choosen or not vector factT;//save factorial numberpublic: string getPermutati

2013-05-31 10:38:46 1271

#### 原创 [LeetCode]Path Sum II

struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {//record all the path, though dfs is not time efficient bu als

2013-05-31 10:38:41 1016

#### 原创 Sorting

A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. There are two mainly kind of sorting algori

2013-05-31 10:37:51 1490

#### 原创 [LeetCode]Reverse Linked List II

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}}; class Solution {//divide this problem into 3 parts//1. previous part, do not need to reverse//2. median pa

2013-05-31 02:39:59 1270

class Solution {//DFS//Note: there are 4 special process herepublic: void DFS(int curStep, int curPos, const string& s, string& curAns, vector& ans) { if(s.size()-curPos > (5-curStep)*3)//3. cu

2013-05-31 02:39:50 2176

#### 原创 [LeetCode]Path Sum

struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution { //if we need to find one path sum of a tree, then dfs is alway

2013-05-30 10:27:47 679

#### 原创 [LeetCode]Pascal Triangle II

class Solution {public: vector getRow(int rowIndex) { // Start typing your C/C++ solution below // DO NOT write int main() function vector ans(rowIndex+2, 0); vector tmp(ro

2013-05-30 10:27:40 749

#### 原创 [LeetCode]Pascal's Triangle

class Solution {public: vector > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > ans; ans.resize(numRows);

2013-05-30 10:27:34 1459

#### 原创 [LeetCode]Partition List

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {public: ListNode *partition(ListNode *head, int x) { // Start typing your C/C++ solution b

2013-05-30 10:27:30 1405

#### 原创 [LeetCode]Palindrome Partitioning II

class Solution {public: int minCut(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int len = s.size(); vector dp(len+1);//dp[i]: minimum cut between

2013-05-30 10:27:24 1400

#### 原创 [LeetCode]Palindrome Partitioning

class Solution {public: bool IsPalindrome(string str, int startIdx, int endIdx) { while (startIdx < endIdx) { if(str[startIdx] != str[endIdx]) return false; startIdx++; endIdx--;

2013-05-30 10:26:06 1093

#### 原创 [LeetCode]Palindrome Number

class Solution {//compare both the left most and the right most digit, //if not equal return falsepublic: bool isPalindrome(int x) { // Start typing your C/C++ solution below // DO NOT write i

2013-05-30 10:26:01 3504 4

#### 原创 [LeetCode]Next Permutation

class Solution {//from right to left find the minimum larger number to replace the current number//once find, swap(current, minimum larger number), then sort(current+1, end)//find out the regular p

2013-05-30 10:25:57 1476

#### 原创 [LeetCode]N-Queens II

class Solution {//http://www.matrix67.com/blog/archives/266//need more practice, solve N-Queens by bit manipulationpublic: int cnt,upper; int totalNQueens(int n) { // Start typing your C/C++ s

2013-05-30 10:25:53 1323

#### 原创 [LeetCode]N-Queens

class Solution {//using DFS//CheckPosition part may can be optimizedpublic: vector > solveNQueens(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(0

2013-05-30 10:25:48 1786

#### 原创 [LeetCode]Multiply Strings

class Solution {//draw it out and then observe it to find out the regular pattern//more practice is neededpublic: string multiply(string num1, string num2) { // Start typing your C/C++ solution

2013-05-30 10:25:43 1811

#### 原创 [LeetCode]Minimum Window Substring

class Solution {//need2FT + hasFT + two pointer + count(check if satisfied)//O(n)public: string minWindow(string S, string T) { // Start typing your C/C++ solution below // DO NOT write int ma

2013-05-30 10:25:29 1811 2

#### 原创 [LeetCode]Minimum Path Sum

class Solution {//DPpublic: int minPathSum(vector > &grid) { // Start typing your C/C++ solution below // DO NOT write int main() function int n = grid.size(); if(n == 0) return 0; int m

2013-05-30 10:25:24 1628

#### 原创 [LeetCode]Minimum Depth of Binary Tree

struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution { //find the minimum step of a tree, bfs works at most timepub

2013-05-30 10:25:19 2450

#### 原创 [LeetCode]Merge Two Sorted Lists

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {//this is a very simple implementation//one pointer and one pointer's pointerpublic: ListN

2013-05-30 10:25:12 867

#### 原创 [LeetCode]Merge k Sorted Lists

struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {//O(nlogk)//using priority_queue to choose current minimum node//node: keep priority_queue

2013-05-30 10:24:49 2448 2

#### 原创 [LeetCode]Merge Intervals

struct Interval { int start; int end; Interval() : start(0), end(0) {} Interval(int s, int e) : start(s), end(e) {}};class Solution {//first sort and then merge, O(nlogn)public: struct comp

2013-05-30 10:24:45 1412

#### 原创 [LeetCode]Median of Two Sorted Arrays

class Solution {//more detail refer to: http://fisherlei.blogspot.com/2012/12/leetcode-median-of-two-sorted-arrays.html//using the method of getting the kth number in the two sorted array to solve t

2013-05-30 10:24:31 1507

#### 原创 Dynamic Programming

Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems andstores the results of subproblems to avoid computing the same results again. Follo

2013-05-30 10:22:54 1004

#### 原创 [LeetCode]Merge Sorted Array

class Solution {//write down some cases and find out the regular patternpublic: void merge(int A[], int m, int B[], int n) { // Start typing your C/C++ solution below // DO NOT write int main()

2013-05-30 02:24:55 716

2011-12-06

2011-04-02

2011-04-02

2010-05-11

2010-04-19

2009-08-20

2009-08-04

2009-08-04

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-10

2009-03-09

2009-03-09

#### 链表C语言实现 功能齐全

/* head 为链表的头指针，也就是第一个节点的地址，只有在加入第一个节点的时候有用 last 是这样一个节点，当你输入数据的时候，内存首先开辟一个区域，此时，last指向上一个节点的地址 curPosi 永远指向当前新开辟的区域，一旦指向当前新开辟的区域，那么curPosi 就和以前的所有节点没有关系了 为了让last永远指向上一个节点，在给last的 next指针赋值之后，last要指向当前节点 */

2009-03-09