C++
一袖云
这个作者很懒,什么都没留下…
展开
-
C++指针和引用的区别
指针和引用的区别 1.引用不可以为空,但指针可以为空。定义一个引用的时候,必须初始化; 2.引用一旦初始化后不可以再改变指向(但可以改变所指向对象的内容),而指针可以改变指向。 3.引用的大小是所指向的变量的大小,因为引用只是一个别名而已;指针是指针(地址)本身的大小,32位系统下,一般为4个字节。 4.引用比指针更安全。由于不存在空引用,并且引用一旦被初始化为指向一个对象,它就不能被改变...原创 2018-08-20 10:13:59 · 1635 阅读 · 0 评论 -
聊聊C++关键字const
面试的时候被问到const关键字,我只说出了几条,没说全,感觉面试官很不满意,回去就恶补了一下,现在跟大家分享一下: (1)const变量和对象一旦定义就不能改变,故必须初始化 (2)默认状况下,const对象只在文件内有效。如果想在多个文件共享const对象就必须在变量定义前加extern关键字 (3)const的引用:把引用绑定到const上就像绑定到其他对象上一样,称之为对常量的引...原创 2018-08-28 15:03:41 · 128 阅读 · 0 评论 -
Parlindrome-Partitioning
class Solution { public: vector<vector<string>> partition(string s) { vector<vector<string>> res; vector<string> cur;原创 2018-08-21 21:32:39 · 212 阅读 · 0 评论 -
求【1...N】的全排列
对于部分有序数组,想要寻找最大值,最简单的方法是遍历,时间复杂度为O(n),但我们可以由有序性想到利用二叉查找,比如:对于一个先升后降数组,寻找其中最大值 for example: input:1 2 3 4 5 6 6 1 output:6 input: 1 2 3 4 5 6 7 8 9 6 4 3 2 1 output: 9 这是一道面试题,现在整理如下: #include&l...原创 2018-09-05 23:42:57 · 384 阅读 · 0 评论 -
单链表排序
单链表排序 初始化: #include <stdio.h> #include <stdlib.h> #include <stdbool.h> //节点结构 struct node { int val; struct node * next; }; typedef struct node node, * list; //打印函数 void pr...转载 2018-10-10 09:42:01 · 604 阅读 · 0 评论 -
剑指offer:找出数组中只出现一次的两个数字
一个整型数组里除了两个数字之外,其他的数字都出现了偶数次。请写程序找出这两个只出现一次的数字。 #include<unordered_map> class Solution { public: //num1和num2分别保存这两个只出现一次的数字 void FindNumsAppearOnce(vector<int> data,int* num1,int *num2...原创 2018-10-10 10:48:19 · 181 阅读 · 0 评论 -
leetcode: 删除链表中的冗余结点
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Input: 1->2->3->3->4->4->5 Output: 1->2-...原创 2018-10-10 11:28:10 · 331 阅读 · 0 评论