- 博客(38)
- 收藏
- 关注
原创 类型转换
算术转换:把一种算术类型转换成另一种算术类型。运算符的运算对象将转换成最宽的类型,题中最宽的是double类型8字节,所以结果是double。 其他几种转换情况: 1、整型提升:把小整数类型转换成较大的整数类型。其中布尔值false提升为0、true提升为1; 2、无符号类型的运算对象: 如果一个运算对象是无符号类型、另一个是带符号类型
2017-08-31 20:11:53 294
转载 sizeof的使用
Sizeof的作用非常简单:求对象或者类型的大小。然而sizeof又非常复杂,它涉及到很多特殊情况,本篇把这些情况分门别类,总结出了sizeof的10个特性:(0)sizeof是运算符,不是函数;(1)sizeof不能求得void类型的长度;(2)sizeof能求得void类型的指针的长度;(3)sizeof能求得静态分配内存的数组的长度!(4)sizeof
2017-08-31 19:54:56 529
原创 多态
多态包含静态与动态两种,静态指编译时多态,动态指运行时多态编译时多态:在c++中主要体现在函数模板中函数重载与编译时多态无关。多态举例:templateT add(T x,T y){ T c=x+y; return c;}运行时多态:主要体现在虚函数中子类覆盖或者改写父类中的成员函数。如:#include using namespace s
2017-08-31 19:38:13 227
原创 c++ 宏、不可重载运算符、抽象类
1.宏只是预定义的函数,在编译阶段不进行类型安全性检查,在编译的时候将对应函数用宏命令替换。对程序性能无影响不能绝对的说宏会带来性能损失他是不确定的,要根据你使用的情况比如,调用函数式宏不需要入栈出栈,所以一般情况下,性能会提高点,但是如果使用不当,就会降低性能宏可以做到函数无法做到的功能2.C++中不能重载的运算符:“ ?: ”、 “ . ”、“ :: ”
2017-08-31 14:37:21 416
转载 c++指针中0,NULL和nullptr
转载地址:史上最明白的 NULL、0、nullptr 区别分析C的NULL在C语言中,我们使用NULL表示空指针,也就是我们可以写如下代码:int *i = NULL;foo_t *f = NULL;实际上在C语言中,NULL通常被定义为如下:#define NULL ((void *)0)也就是说NULL实际上是一个void *的指针
2017-08-31 12:44:02 1766
原创 49. Group Anagrams(哈希表second)
题目:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]代
2017-08-25 17:48:03 555
原创 46. Permutations(全排列)
题目:Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],
2017-08-24 19:26:37 205
原创 96. Unique Binary Search Trees(通过观察递推式意思找递推关系)
题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1
2017-08-20 16:24:03 224
原创 91. Decode Ways
题目:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the
2017-08-20 16:03:12 124
原创 87. Scramble String(三维动态规划+形似map的数组使用技巧)
题目:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great /
2017-08-20 14:34:05 355
原创 85. Maximal Rectangle 一行一行遍历方形
题目:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1
2017-08-19 19:05:03 209
原创 72. Edit Distance(动态规划中二维降一维)
题目:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted o
2017-08-19 16:42:33 2176
原创 62. Unique Paths&&63. Unique Paths II 路径
Unique Paths题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is
2017-08-19 14:34:38 178
原创 32. Longest Valid Parentheses
题目:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is
2017-08-18 20:18:57 148
原创 排序之插入排序
步骤:将序列分成有序区和无序区,通过将无序区的数不断加入有序区并保持有序,完成排序代码:void SelectionSort(vector& num){ int size = num.size(); int i, j; int temp; for (i = 1; i<size; i++){ j = i; if (num[j] < num[j - 1])
2017-08-16 19:54:33 193
原创 排序之选择排序
步骤:是冒泡排序的优化,因为函数调用是压栈的,繁杂操作浪费内存选择排序每轮只交换一次元素,从尾至头找到最小的然后与第一个交换代码:void SelectionSort(vector& num){ int size = num.size(); for (int i = 0; i<size; i++){ int min = i; for (int j = i + 1
2017-08-16 19:35:24 168
原创 排序之冒泡排序
步骤:从数列尾部开始,相邻元素比较大小,小的向前移动每一轮移动至前面的数字按顺序排列下来代码:void BubbleSort(vector& num){ int size = num.size(); for (int i = 0; i < size; i++){ for (int j = size - 1; j>i; j--){ if (num[j] < num[j
2017-08-16 19:19:17 166
原创 22. Generate Parentheses(括号的压入)
题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()",
2017-08-16 13:58:56 181
原创 源码到可执行文件过程
1.c++中,声明const int i,是在编译做到 i只可读的2.由多个源文件组成的C程序,经过编辑、预处理、编译、链接等阶段会生成最终的可执行程序。链接阶段可以发现被调用的函数未定义解析:const用来说明所定义的变量是只读的。 这些在编译期间完成,编译器可能使用常数直接替换掉对此变量的引用。源代码到可执行文件的过程源代码-->预处理-->编译-->优化-->汇编--
2017-08-15 20:20:47 355
原创 排序之快速排序
首先给出一个概念原址排序:算法在数组A中重排这些数,在任何时候,最多只有其中的常数个字存储在数组外面常见原址排序有 快排,堆排,冒泡等等,归并不是原址排序时间复杂度:快排期望的时间复杂度是O(nlogn) ,最坏情况为O(n^2)例如常用到的left,mid,right二分查找的思想,可以看做是一种快排快排的最坏情况就是每次划分都是n-1 与0 两个规模,此时时间
2017-08-15 16:03:48 177
原创 从尾到头打印链表
首先想到是改变链表结构,使其从尾指向头逆序链表:ListNode* ListReverse(ListNode *head){ if(head==NULL||head->next==NULL) return head; ListNode *p->next=head; ListNode *current,*pre=head; current=pre->next;
2017-08-15 14:42:19 125
原创 赋值运算符
对于赋值运算符正常需要考虑4点1.传入参数是否是常量引用2.返回类型是否是类的引用3.是否释放自身已占的内存4.是否考虑自赋值强开对于异常安全性,正常赋值运算符如下CMyString& CMyString::operator = (const CMyString &other) { if (this == &other) { return *
2017-08-14 10:56:32 218
转载 三五法则以及行为像值的类和行为像指针的类
转载链接:http://blog.csdn.net/ysayk/article/details/51056431#comments文章作者:XDmonkey首先我们说明有三个基本操作可以控制类的拷贝操作:拷贝构造函数、拷贝赋值运算符(这两个的区别之前有文章讲到)、以及析构函数。 那么我们什么时候需要自己构建拷贝构造函数和重载拷贝赋值运算符呢,在三/五法则中给出了自
2017-08-12 19:32:47 495
原创 139. Word Break
题目:Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. Y
2017-08-12 13:24:52 130
原创 13.1.1 析构函数
构造函数与析构函数都不对static(静态)变量起作用class A{ ~A(); //析构函数}因为析构函数没有参数,所以不能被重载,所以一个类只存在一个析构函数销毁类类型成员时(即一个类中的某个成员是类),调用该成员自己的析构函数,对于内置类型(例如Int) 析构时什么都不用做Q:析构顺序?构造函数按成员在类中的出现顺序初始化 析构函数逆序Q:
2017-08-11 20:06:02 209
原创 13.1.2 拷贝赋值运算符
拷贝构造函数即构造某一类型,下面所示只是拷贝构造函数的声明,其定义形式如:A::A(const A& test): a(test.a);class A{ public: A(); //默认构造函数 A(const A&); //拷贝构造函数 private: int a;}; 拷贝赋值运算符,即让两个类型相等如: A a,b
2017-08-11 19:50:38 234
原创 13.1.1 拷贝构造函数
Q:什么是拷贝构造函数?一个构造函数的第一个参数是其自身类类型的引用,其任何参数都有默认值class A{public: A(); //默认构造函数 A(const A&); //拷贝构造函数};Q:为什么第一个参数前要加const ,为什么必须是引用1.因为接受的参数几乎总是一个const的引用,且拷贝构造函数在某种情况下会被隐式使用(explicit),
2017-08-11 19:38:56 284
原创 17. Letter Combinations of a Phone Number
题目:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input
2017-08-08 20:13:04 173
原创 40. Combination Sum II
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in th
2017-08-08 14:32:09 175
原创 39. Combination Sum
题目:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be
2017-08-07 21:05:05 147
原创 79. Word Search
题目:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or v
2017-08-07 14:43:50 155
原创 77. Combinations
题目:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [
2017-08-04 17:15:35 147
原创 51. N-Queens
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens
2017-08-04 16:01:26 248
原创 73. Set Matrix Zeroes
题目:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probabl
2017-08-04 14:45:20 202
原创 127. Word Ladder
题目:Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermedia
2017-08-03 22:15:43 198
原创 53. Maximum Subarray 最大子序列和
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-
2017-08-01 20:00:56 167
原创 45. Jump Game II
题目:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Yo
2017-08-01 18:49:21 190
原创 19. Remove Nth Node From End of List
题目:Given a linked list, remove the nth node from the end of list and return its head.设置两个结点pre,post,先走的结点pre走n步,然后两个结点一起走,当pre到达末尾的时候post->next恰好是要删除的结点注意两个陷阱1.设置pre 和 post的n
2017-08-01 14:24:31 162
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人