自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(45)
  • 收藏
  • 关注

原创 ZigZag Conversion

class Solution {public:    string convert(string s, int numRows) {              string result;         int base;         base=2*numRows-2;         if(numRows          if(s.size()   

2015-07-30 20:17:39 160

原创 Longest Substring Without Repeating Characters

class Solution {public:    int lengthOfLongestSubstring(string s) {        int len=s.size();        if(s.size()==0) return 0;        int max1=1;        int count;        int j=0;     

2015-07-30 18:13:31 189

原创 Implement strStr()

class Solution {public: vectorint> KMPpreprocessing(char *s) { int n = strlen(s); vectorint> match(n,-1); int j = -1; for(int i=1; in; i++) { while(j>=

2015-07-29 20:49:00 167

原创 Longest Common Prefix

class Solution {public:    string longestCommonPrefix(vector& strs) {        string result;        if(strs.size()        if(strs.size()==1) return strs[0];        sort(strs.begin(),strs.en

2015-07-29 11:10:33 127

原创 Valid Palindrome

class Solution {public:    bool isPalindrome(string s) {        if(s==" ") return true;        if(s.size()==1) return true;        int len=s.size();        int i,j;        for(i=0,j=len-

2015-07-27 20:34:19 123

原创 Set Matrix Zeroes

class Solution {public:    void setZeroes(vector>& matrix) {        vector> ivec(matrix);                int m=matrix.size();        int n=matrix[0].size();        vector zero(n,0);   

2015-07-22 19:50:17 149

原创 Kth Smallest Element in a BST

class Solution {public:      vectorresult;      int count=0;      int res=0;    int kthSmallest(TreeNode* root, int k) {                posttraverse(root,k);                return re

2015-07-22 16:42:20 120

原创 LeetCode Rotate Image旋转图像

Rotate ImageYou are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?其实题目更好理解为旋转一个矩阵的下标90°。实际问题实际分析,这里不用

2015-07-22 15:40:03 176

原创 Add Binary

class Solution {public:    string addBinary(string a, string b) {                  int len1=a.size();         int len2=b.size();         int min1=min(len1,len2);         int cf=0;     

2015-07-22 11:57:55 153

原创 Add Binary

class Solution {public:    string addBinary(string a, string b) {                  int len1=a.size();         int len2=b.size();                  string s;     int result=stoi1(a)+stoi

2015-07-22 10:51:56 133

转载 Single Number II

题目描述:给定一个包含n个整数的数组,除了一个数出现一次外所有的整数均出现三次,找出这个只出现一次的整数。题目来源:http://oj.leetcode.com/problems/single-number-ii/题目分析:对于除出现一次之外的所有的整数,其二进制表示中每一位1出现的次数是3的整数倍,将所有这些1清零,剩下的就是最终的数。用ones记录到当前计算的变量为止,二进制1出现“1次”(m

2015-07-22 08:41:31 155

原创 Minimum Path Sum

class Solution {public:    int minPathSum(vector>& grid) {        if(grid.size()==0) return 0;        int m=grid.size();        int n=grid[0].size();       int sum=0;       for(int j=1;j

2015-07-21 17:05:23 249

原创 Search in Rotated Sorted Array

class Solution {public:    int search(vector& nums, int target) {        if(nums.size()==0)return -1;        if(nums.size()==1&&target==nums[0]) return 0;        if(nums.size()==1&&target!=n

2015-07-21 10:37:11 138

原创 Maximum Subarray

class Solution {public:    int maxSubArray(vector& nums) {        if(nums.size()==0) return 0;        int sum=0;               int len=nums.size();        int result=INT_MIN;        fo

2015-07-20 22:51:04 185

原创 Find Minimum in Rotated Sorted Array II

class Solution {public:    int findMin(vector& nums) {            if(nums.size()==1) return nums[0];        int len=nums.size();        for(int i=1;i        {            if(nums[i]   

2015-07-20 20:19:23 154

原创 Pascal’sTriangleII

classSolution{public:vectorgetRow(introwIndex){vectorarray;for(int i=0;i{for(int j=i-1;j>0;j--){array[j]=array[j-1]+array[j];}array.push_back(1);}returnarray;}};

2015-07-19 21:02:22 284

原创 Best Time to Buy and Sell Stock III

class Solution {public:    ///设状态 f ( i ),表示区间 [0 , i ](0 ≤ i ≤ n − 1) 的最大利润,从前向后遍历(表示i之前的数组的最大利润),用最大的-最小的    //状态 g ( i ),表示区间 [ i, n − 1](0 ≤ i ≤ n − 1) 的最大利润,从后向前遍历(表示i之后的数组的最大利润),也用最大的-最小的

2015-07-19 19:35:44 175

原创 Best Time to Buy and Sell Stock

class Solution {public:    int maxProfit(vector& prices) {            if(prices.size()            int max1=INT_MIN;        int min1=prices[0];        for(int i=1;i         {       

2015-07-19 16:14:57 188

原创 sprintf函数用法

sprintf() 格式化输出函数(图形)功能: 函数sprintf()用来作格式化的输出。用法: 此函数调用方式为int sprintf(char *string,char *format,arg_list);说明: 函数sprintf()的用法和printf()函数一样,只是sprintf()函数给出第一个参数string(一般为字符数组),然后再调用outtextxy()函数将串

2015-07-19 15:42:47 238

原创 Summary Ranges

class Solution {public:    vector summaryRanges(vector& nums) {        vector> result;        vectorivec;        vectorresult1;        int len=nums.size();        int i=0;           

2015-07-19 15:37:01 199

原创 Majority Element II

class Solution {public:    vector majorityElement(vector& nums) {       vectorivec;       int num1=0,num2=0,cnt1=0,cnt2=0;       int len=nums.size();       for(int i=0;i       {       

2015-07-19 11:14:03 138

原创 4 sum

做过leetcode的人都知道, 里面有2sum, 3sum(closest), 4sum等问题, 这些也是面试里面经典的问题, 考察是否能够合理利用排序这个性质, 一步一步得到高效的算法. 经过总结, 本人觉得这些问题都可以使用一个通用的K sum求和问题加以概括消化, 这里我们先直接给出K Sum的问题描述和算法(递归解法), 然后将这个一般性的方法套用到具体的K, 比如leetcode中的2

2015-07-19 10:17:25 250

原创 3Sum

class Solution {public:    vector> threeSum(vector& nums) {               vector>result;       if(nums.size()       vectorivec;        sort(nums.begin(),nums.end());        int len=num

2015-07-18 16:12:18 187

原创 Contains Duplicate II

class Solution {public:    bool containsNearbyDuplicate(vector& nums, int k) {        multimapmmap;       typedef multimap::iterator iter;        int i=0;        for(i=0;i        mmap.in

2015-07-17 16:12:43 321

原创 Jump Game II

class Solution {public:    int jump(vector& nums) {        if(nums.size()==1) return 0;                int maxreach=nums[0];        int step=1;        int start=0,newmax=0;       while

2015-07-16 14:28:20 131

原创 Jump Game

class Solution {public:    bool canJump(vector& nums) {                int i=0;        int len=nums.size();        bool a[len+1]={0};                                   //开辟新数组,表示每格的可达性; 

2015-07-16 10:46:23 207

原创 【源码剖析】tinyhttpd —— C 语言实现最简单的 HTTP 服务器

tinyhttpd 是一个不到 500 行的超轻量型 Http Server,用来学习非常不错,可以帮助我们真正理解服务器程序的本质。    看完所有源码,真的感觉有很大收获,无论是 unix 的编程,还是 GET/POST 的 Web 处理流程,都清晰了不少。废话不说,开始我们的 Server 探索之旅。    (水平有限,如有错误之处,欢迎指正)     项

2015-07-16 09:27:40 685

原创 HTTP协议详解

HTTP协议详解2007-03-08 16:57 111623人阅读 评论(80) 收藏 举报服务器http服务器authorization浏览器serverweb服务Author :Jeffrey  My Blog:http://blog.csdn.net/gueter/ 引言                                        

2015-07-16 09:26:30 265

原创 webbench

webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好用,安装使用也特别方便,并且非常小。主要是 -t 参数用着比较爽,下面参考了张宴的文章:  1、适用系统:Linux  2、编译安装:1234[root@hexuweb102 ~]$wget http://blog.s135.com/soft/linu

2015-07-15 21:57:31 235

原创 Merge k Sorted Lists

class Solution {public:    ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {        ListNode *helper=new ListNode(0);        ListNode *head=helper;        while(l1 && l2)        {

2015-07-13 16:54:42 140

原创 Partition List

class Solution {public:    ListNode* partition(ListNode* head, int x) {        if(head==NULL||head->next==NULL) return head;        queueQ1;        ListNode* p=head,*pre=head,*plast,*pre1;

2015-07-13 11:20:18 233

原创 Remove Linked List Elements

class Solution {public:    ListNode* removeElements(ListNode* head, int val) {        if(head==NULL) return NULL;        ListNode *head1,*p,*pre;        head1=head;        while(head1&&hea

2015-07-13 10:29:34 275

原创 Linked List Cycle

class Solution {public:    ListNode *detectCycle(ListNode *head) {                   if(NULL==head) return head;        if(head->next==head) return head;        if(NULL==head->next) retu

2015-07-12 16:12:27 158

原创 Palindrome Linked List

class Solution {public:    bool isPalindrome(ListNode* head) {        if(NULL==head||NULL==head->next) return 1;                int len=0;        stacks;        ListNode *temp,*p=head;

2015-07-12 15:40:04 305

原创 Remove Nth Node From End of List

class Solution {public:    ListNode* removeNthFromEnd(ListNode* head, int n) {        if(head==NULL) return nullptr;        if(head->next==NULL) return nullptr;        ListNode *p1=head,*p2,

2015-07-12 14:58:20 285

原创 Intersection of Two Linked Lists

class Solution {public:    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {                       ListNode *p1=reverseList(headA);        ListNode *p2=reverseList(headB);

2015-07-11 20:32:21 354

原创 Reverse Nodes in k-Group

class Solution {public:    ListNode* reverseKGroup(ListNode* head, int k) {        ListNode* p=head;        int len=0;         if(head==NULL||head->next==NULL) return head;        while(p)

2015-07-11 20:30:02 148

原创 Reverse Linked List II

class Solution {public:    ListNode* reverseList(ListNode* head) {         if(head==NULL) return head;        if(head->next==NULL)  {return head;}                  ListNode*  p=head;   

2015-07-11 15:16:55 156

原创 Reverse Bits

class Solution {public:    uint32_t reverseBits(uint32_t n) {         int a;        long ret=0;        int i=0;                do {            a=n%2;            ret=ret*2+a;       

2015-07-11 11:17:42 249

原创 Word Ladder II?

class Solution {public:            vector next(string &s,unordered_set &dict)     {          vectorresult;          string temp=s;          int len = temp.size();         // unordere

2015-07-10 21:07:32 170

空空如也

空空如也

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

TA关注的人

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