自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

大洋深处

爱生活,爱算法,爱coding

  • 博客(18)
  • 资源 (1)
  • 收藏
  • 关注

原创 剑指offer 链表中倒数第k个结点

题目: 输入一个链表,输出该链表中倒数第k个结点。解析:怎么在遍历一次的前提下就能求得链表的倒数第k个结点呢?可以设置两个指针,p和q,并且都将其初始值置为头p = q = pListHead;然后让p先走k-1步,那么就到了正数第k个结点,然后这时候让p和q同时走,直到p的下一个结点为空,因为设链表长度为L,那么q到底走了多长呢?q走的长度为链表长度减去p第二次走的长度,即为...

2018-05-31 10:46:48 215

原创 条款03:尽可能使用const

条款03:尽可能使用constconst的一件奇妙事情是,它允许你指定一个语义约束(也就是指定一个“不被改动”的对象),而编译器会强制实施这项约束修饰指针面对指针,可以指出指针自身,指针所指物或两者都(或都不)是const char greeting[] = "Hello"; char *p = greeting; //非常量指针,非常量数据 const char* ...

2018-05-29 23:57:24 138

原创 Leetcode42 Trapping Rain Water

题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by...

2018-05-25 23:18:24 150

原创 Leetcode_11 Container With Most Water

Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two li...

2018-05-22 22:04:21 109

原创 一个有趣的问题 n取余10 =9 n取余9 = 8 n取余8=7 求n n在100到1000之间

这个题目很有意思 ,首先分析n%10 = 9 n%9 =8 n%8=7,那么设这个数为s 那么s+1就能被10 9 8整除 , 又10 9 8 的最小公倍数为360,所以在100~1000之间,只有两个数满足条件,360,720,故s= 359,719...

2018-05-21 21:20:25 1171

转载 C++的顶层const和底层const的理解

转发来自:https://blog.csdn.net/qq_19528953/article/details/50922303#t0最近,又一次翻开C++primer,决定仔细研究一下自己以前没搞懂的顶层const和底层const,这次看了后感觉明白了,所以记录下来,以后可以没事翻阅,增加记忆。首先,const是一个限定符,被它修饰的变量的值不能改变。对于一般的变量来说,其实没有顶层const...

2018-05-21 20:42:54 258

原创 Leetcode_10 Regular Expression Matching

题目: Given an input string (s) and a pattern (p), implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding elem...

2018-05-19 23:02:13 127

原创 Leetcode_234. Palindrome Linked List

题目: Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2 Output: falseExample 2:Input: 1->2->2->1 Output: trueFollow up: Could you do it in O(n) ...

2018-05-18 23:29:42 116

原创 一个简单的Screen类对其进行内存管理(重载operatore new和operator delete)

代码:#include<iostream>#include<cstring>#include<vector>using namespace std;class Screen{public: Screen(int x):i(x){}; int get() {return i;} static void* operator ...

2018-05-18 10:30:35 264

原创 二维vector的两种初始化方式

二维vector的两种初始化方式第一种一行直接申明vector<vector<char> >vec(row,vector<char>(col,'#'));这里的row,col代表二维vector的两个轴方向的大小第二种方式vector<vector<char> >vec1;vec1.resize(row);...

2018-05-16 13:23:04 11961

原创 Leetcode_6 ZigZag Conversion

The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N A P L S I I...

2018-05-16 13:11:15 102

原创 C++ 内存管理之重载operator new 和operator delete

当我们在C++中使用new 和delete时,其实执行的是全局的::operator new和::operator delete。首先我们来看一个简单的例子。class Foo{...}Foo* pf = new Foo;delete pf上面的代码底层执行的是什么呢?首先new包含两阶段的操作。 (1)首先调用::operator new分配内存 (2)调用Foo::Fo...

2018-05-15 19:52:02 13946 4

原创 Leetcode_5 solve Longest Palindromic Substring

题目: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: “babad” Output: “bab” Note: “aba” is also a valid answer....

2018-05-14 22:04:40 94

原创 构造函数之无参构造函数

首先看一段代码:#include<iostream>using namespace std;struct Foo{ Foo() {} Foo(int) {} void fun(){}};int main(){ Foo a(10); a.fun(); Foo b(); b.fun(); return...

2018-05-14 14:50:11 3434

原创 Leetcode_4. Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]...

2018-05-13 21:59:29 334

原创 Leetcode_3. Longest Substring Without Repeating Characters

题目: Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”,...

2018-05-13 20:54:28 71

原创 堆排序

堆排序是一种比较常见的排序方法。 最重要的是建立初始堆的过程。然后一次调整会有一个最大值,那么和尾元素对调,那么堆失去平衡,重新进行调整,其实调整的时候因为是在已经建好的堆上进行调整,所以每次只需要调整a[0]元素即可。 代码:#include<iostream>#include<cstdio>#include<cstring>using na...

2018-05-13 16:08:54 95

原创 Tinyhttpd的实现和一些基本问题的解决

TInyhttpd是一个简单的http服务器的实现,代码总共有500多行,但是读下来对http的具体实现过程和linux网络编程的学习都很有好处。我重写了代码,然后进行了详细的注释。注释见详细代码。 具体的可以用图表示: 代码:/*#!/usr/bin/env* ******************************************************* Last...

2018-05-07 21:26:55 1640 5

邮件收发系统

是基于web的邮件收发系统

2016-04-04

空空如也

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

TA关注的人

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