![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 59
daisyZH
微博:http://weibo.com/daisyzhuan
展开
-
KMP算法
转自:http://www.cnblogs.com/dolphin0520/archive/2011/08/24/2151846.html在介绍KMP算法之前,先介绍一下BF算法。一.BF算法BF算法是普通的模式匹配算法,BF算法的思想就是将目标串S的第一个字符与模式串P的第一个字符进行匹配,若相等,则继续比较S的第二个字符和P的第二个字符;若不相等,则比较S的第二个字符和P的第一转载 2013-09-21 17:36:41 · 615 阅读 · 0 评论 -
leetcode之Search for a Range
class Solution {public: int bsearch(int A[], int beg, int end, int target) { if (beg>end) { return -1; } int mid = (beg+end)/2; if (A[mid]==targ原创 2013-09-14 20:55:43 · 706 阅读 · 0 评论 -
leetcode之Search a 2D Matrix
class Solution {public: bool searchMatrix(vector > &matrix, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function int m = matrix原创 2013-09-14 20:34:57 · 527 阅读 · 0 评论 -
一般函数指针和类的成员函数指针
转载请注明原文网址: http://www.cnblogs.com/xianyunhe/archive/2011/11/26/2264709.html函数指针是通过指向函数的指针间接调用函数。函数指针可以实现对参数类型、参数顺序、返回值都相同的函数进行封装,是多态的一种实现方式。由于类的非静态成员函数中有一个隐形的this指针,因此,类的成员函数的指针和一般函数的指针的表现形式不一样。转载 2013-09-15 12:00:22 · 435 阅读 · 0 评论 -
leetcode之Spiral Matrix
转自:http://blog.csdn.net/martin_liang/article/details/8982562Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the转载 2013-09-14 21:57:55 · 584 阅读 · 0 评论 -
leetcode之Search Insert Position
class Solution {public: int core(int A[], int beg, int end, int target) { if (beg==end && A[beg] return beg+1; } if (beg==end&&A[beg]>target) {原创 2013-09-14 10:19:15 · 569 阅读 · 0 评论 -
leetcode之Valid Parentheses
class Solution {public: bool isValid(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int n = s.size(); if (n==0) {原创 2013-09-13 18:44:27 · 487 阅读 · 0 评论 -
leetcode之Merge Two Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2013-09-05 15:48:46 · 486 阅读 · 0 评论 -
leetcode之Longest Palindromic Substring
泪奔了,改了一个边界条件就华丽丽的通过了~在这之前,做了好多无用功,只想说一句,叉~class Solution {public: string longestPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() fu原创 2013-09-09 18:40:19 · 512 阅读 · 0 评论 -
leetcode之Longest Substring Without Repeating Characters
class Solution {private: bool canUse[256];public: int lengthOfLongestSubstring(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function原创 2013-09-09 16:06:04 · 551 阅读 · 0 评论 -
leetcode之Swap Nodes in Pairs
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2013-09-14 23:14:57 · 694 阅读 · 0 评论 -
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 (A==NULL || n原创 2013-09-17 20:47:05 · 698 阅读 · 0 评论 -
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 if (A==NULL||n原创 2013-09-17 23:03:10 · 542 阅读 · 0 评论 -
leetcode之Remove Duplicates from Sorted List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Lis原创 2013-09-17 21:33:20 · 680 阅读 · 0 评论 -
leetcode之Remove Duplicates from Sorted List II
class Solution {public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(A==NULL||n原创 2013-09-17 21:01:29 · 582 阅读 · 0 评论 -
leetcode之Reverse Linked List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Lis原创 2013-09-18 11:27:16 · 653 阅读 · 0 评论 -
leetcode之Rotate Image
转自:http://www.cnblogs.com/graph/archive/2013/07/31/3229056.htmlYou are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:转载 2013-09-18 09:47:29 · 856 阅读 · 0 评论 -
leetcode之Roman to Integer
转自:http://blog.csdn.net/wyc1230/article/details/7263055Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.[cpp] view plaincop转载 2013-09-18 10:17:50 · 628 阅读 · 0 评论 -
leetcode之Rotate List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2013-09-18 08:59:43 · 628 阅读 · 0 评论 -
leetcode之Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2013-09-17 20:12:20 · 646 阅读 · 0 评论 -
leetcode之Remove Nth Node From End of List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2013-09-17 22:52:29 · 572 阅读 · 0 评论 -
leetcode之Interleaving String
转自:http://blog.unieagle.net/2012/09/29/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Ainterleaving-string%EF%BC%8C%E4%BA%8C%E7%BB%B4%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/LeetCode题目:Interleaving String,二维转载 2013-09-09 17:40:07 · 893 阅读 · 0 评论 -
Leetcode 4 Median of Two Sorted Arrays
转载:http://blog.csdn.net/zxzxy1988/article/details/8587244今天发现了leetcode上面一道题,觉得非常经典,记录之。题目是这样的:给定两个已经排序好的数组(可能为空),找到两者所有元素中第k大的元素。另外一种更加具体的形式是,找到所有元素的中位数。本篇文章我们只讨论更加一般性的问题:如何找到两个数组中第k大的元素?不过,转载 2013-09-09 14:05:06 · 585 阅读 · 0 评论 -
leetcode之Path Sum
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla原创 2013-09-08 11:21:55 · 607 阅读 · 0 评论 -
leetcode之subsets
#include #include using namespace std;void dfs(int depth, vector& s, vector >& res, vector a, int start) { res.push_back(a); if (depth == s.size()) return; for (int i = sta原创 2013-09-07 20:00:03 · 607 阅读 · 0 评论 -
leetcode之same tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla原创 2013-09-08 11:44:45 · 629 阅读 · 0 评论 -
leetcode之Pow(x, n)
class Solution {public: bool equal(double x, double y) { if (abs(x-y) return true; } return false; } double pow(double x, int n) { //原创 2013-09-07 18:03:40 · 624 阅读 · 0 评论 -
leetcode之Palindrome Partitioning
class Solution {public: bool isPal(string s) { if (s.size() return true; } int beg=0; int end=s.size()-1; while (beg if(s[原创 2013-09-08 15:15:42 · 500 阅读 · 0 评论 -
leetcode之Reverse Linked List II
#include #include struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; ListNode *reverseBetween(ListNode *head, int m, int n) {原创 2013-09-07 19:12:24 · 571 阅读 · 0 评论 -
leetcode之atoi
class Solution {public: int atoi(const char *str) { // Start typing your C/C++ solution below // DO NOT write int main() function if (str == NULL) { retu原创 2013-09-06 19:32:42 · 546 阅读 · 0 评论 -
leetcode之Same Tree
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla原创 2013-09-06 16:51:26 · 488 阅读 · 0 评论 -
leetcode之sqrt(x)
牛顿迭代法class Solution {public: int sqrt(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if (x return x;原创 2013-09-06 18:27:03 · 516 阅读 · 0 评论 -
leetcode之Path Sum II
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla原创 2013-09-08 11:37:14 · 510 阅读 · 0 评论 -
leetcode之Plus One
class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function if (digits.empty()) {原创 2013-09-08 12:25:49 · 529 阅读 · 0 评论 -
leetcode之Pascal's Triangle II
class Solution {public: vector getRow(int rowIndex) { // Start typing your C/C++ solution below // DO NOT write int main() function vector res; res.push_原创 2013-09-09 11:05:58 · 515 阅读 · 0 评论 -
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 > res; i原创 2013-09-09 10:53:49 · 573 阅读 · 0 评论 -
leetcode之Two Sum
class Solution {public: vector twoSum(vector &numbers, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function vector res;原创 2013-09-09 12:31:31 · 468 阅读 · 0 评论 -
leetcode之Gray code
class Solution {public: vector grayCode(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int size = 1 vector res;原创 2013-09-08 21:55:09 · 563 阅读 · 0 评论 -
leetcode之Edit Distance
class Solution {public: int minDistance(string word1, string word2) { // Start typing your C/C++ solution below // DO NOT write int main() function int len1 = word1.s原创 2013-09-08 21:37:09 · 634 阅读 · 0 评论 -
leetcode之Sum Root to Leaf Numbers
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */cla原创 2013-09-08 17:13:01 · 641 阅读 · 0 评论