
offer刷题之路
文章平均质量分 58
ylh1234
这个作者很懒,什么都没留下…
展开
-
二叉树根据前序遍历和中序遍历重构确定唯一二叉树
代码如下struct TreeNode* reConstructBinaryTree(vector pre,vector in) { int inlen=in.size(); if(inlen==0) return NULL; vector left_pre,right_pre,left_原创 2016-10-10 15:57:31 · 726 阅读 · 0 评论 -
数组中的逆序对
方法1:归并排序class Solution {public: int InversePairs(vector data) { if(data.size() int* copy=new int[data.size()]; //初始化该数组,该数组作为存放临时排序的结果,最后要将排序的结果复制到原数组中 for(un原创 2017-07-22 11:08:50 · 234 阅读 · 0 评论 -
把数组排成最小的数
链接:https://www.nowcoder.com/questionTerminal/8fecd3f8ba334add803bf2a06af1b993来源:牛客网class Solution {public: staticbool compare( conststring &st1,conststring &st2){ string原创 2017-07-20 20:43:18 · 208 阅读 · 0 评论 -
连续子数组的最大和
class Solution {public: int FindGreatestSumOfSubArray(vector array) { if(array.empty()) return 0; int sum = array[0], tempsum = array[0]; //注意初始值 不能设为0 防止只有负数 for原创 2017-07-20 19:54:29 · 181 阅读 · 0 评论 -
万能头文件#include<bits/stdc++.h>
#include #include #include #include #include #include #include #include #include #include #include #include #include 包含以上所有头文件原创 2017-03-24 10:57:58 · 807 阅读 · 0 评论 -
函数内存空间
函数:类的普通函数在实例化时才分配内存空间,虚函数(不论多少个)则维护一个指针指向的虚函数表,指针占4个字节原创 2016-12-21 11:08:56 · 499 阅读 · 0 评论 -
关于引用&的主意
使用引用符号&可以避免参数的拷贝和构造,但是引用对象必须设置到对象的实例。下面举例说明如某个函数如下bool Test(int &a){ if(a>5) return true; else return false;}那么在要调用该函数时,不能直接main.Test(8);而需要 int b=8,mai原创 2016-11-02 21:27:48 · 232 阅读 · 0 评论 -
插入排序C++实现
代码如下,时间复杂度为O(n^2)空间复杂度为O(1)特点:稳定适合简单排序,数据量较小的情况#include#include#include using namespace std;void InsertionSort (int a[],int len){if (a==NULL||len{return ;}for(int j=1;j{int原创 2016-11-17 16:30:36 · 206 阅读 · 0 评论 -
刷题总结
1.写循环判断时,用if,else if要简洁点。尽量使用for循环,for+continue或者while效果类似。2.很多字符问题,通常从末尾处理效率会高很多。原创 2016-09-28 09:34:24 · 292 阅读 · 0 评论 -
二叉树大全
http://blog.youkuaiyun.com/luckyxiaoqiang/article/details/7518888;http://blog.youkuaiyun.com/luckyxiaoqiang/article/details/8701926;转载 2016-10-28 14:59:11 · 212 阅读 · 0 评论 -
字符串反转方法总结
第一种:使用string.h中的strrev函数[cpp] view plain copy#include #include using namespace std; int main() { char s[]="hello"; strrev(s);转载 2017-07-27 15:22:14 · 237 阅读 · 0 评论