- 博客(64)
- 收藏
- 关注
转载 根据输入值定义的数组大小
#include using namespace std; int main() { int *a;int i,n;cout<<"please enter array size:" <<endl ;cin >> n; // 数组大小a = (int *) malloc(sizeof(int) * n); // 分配cout<<"please enter " << n
2014-04-06 19:25:44
2630
转载 latex升级包
1.windows start menuupdate MikTeX2.Selecting packagesamslatex3.在cmd 输入mpm,就会看到有amsmath,amscls包,然后安装,安装完后,多编译几次就可以了,此外,注意thm,def是已经定义过的关键词,得自己重新取名字
2015-03-20 14:32:53
1951
转载 strcpy与strcpy_s的问题
一下是使用strcpy_s与strcpy的安全性比较 char szBuf[2] = {0}; strcpy_s(szBuf, 2, "12131"); //新的CRT函数 strcpy(szBuf, "12131"); //老的CRT函数上述代码,明显有缓冲区溢出的问题。 使用strcpy_s函数则会抛出一个异常。而使用strcpy函数的结果则未定,因为它错误地
2015-01-28 16:16:07
677
转载 mutex和critical section的区别
1、临界区只能用于对象在同一进程里线程间的互斥访问;互斥体可以用于对象进程间或线程间的互斥访问。2、临界区是非内核对象,只在用户态进行锁操作,速度快;互斥体是内核对象,在核心态进行锁操作,速度慢。3、临界区和互斥体在Windows平台都下可用;Linux下只有互斥体可用。1、临界区:通过对多线程的串行化来访问公共资源或一段代码,速度快,适合控制数据访问。2、互斥量:为协调共同对
2014-10-29 11:14:25
655
转载 总结c++笔试题目
1. 关键字static的作用是什么?在C语言中,关键字static有三个明显的作用:1)在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变。2) 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所用函数访问,但不能被模块外其它函数访问。它是一个本地的全局变量。3) 在模块内,一个被声明为静态的函数只可被这一模块内的其它函数调用。那就是,这个
2014-10-29 10:38:54
471
转载 引用和指针详细介绍
C++中引用与指针的区别(详细介绍)C++中的引用与指针的区别 指向不同类型的指针的区别在于指针类型可以知道编译器解释某个特定地址(指针指向的地址)中的内存内容及大小,而void*指针则只表示一个内存地址,编译器不能通过该指针所指向对象的类型和大小,因此想要通过void*指针操作对象必须进行类型转化。 ★ 相同点: 1. 都是地址的概念;
2014-10-29 09:49:57
386
转载 dianmian题目
IO中同步、异步与阻塞、非阻塞的区别2013-05-31 11:51:19 分类: LINUX一、同步与异步同步/异步, 它们是消息的通知机制1. 概念解释A. 同步所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不返回。按照这个定义,其实绝大多数函数都是同步调用(例如sin isdigit等)。但是一般而言,我们在说同步、异步的
2014-10-22 22:08:55
417
转载 bank笔题目记录1
编写汇编语言程序时,下列寄存器中程序员可访问的是(5)。(5) A.程序计数器(PC) B.指令寄存器(OR)C.存储器数据寄存器(MDR) D.存储器地址寄存器(MAR)
2014-10-22 21:33:13
424
转载 笔试2
1.Myclass a[3],*p[2];a[3]中有3个Myclass对象,定义时会各调用Myclass构造函数一次。Myclass *p[2]只定义了两个指针,只是两个指针变量。
2014-09-16 21:43:55
1328
转载 Search a 2D Matrix
Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to ri
2014-09-11 20:27:16
286
转载 Container With Most Water
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 li
2014-09-11 19:32:23
289
转载 Minimum Path Sum
Minimum Path Sumclass Solution {public: vector > f; //备忘录法,把每次计算的值保存下来 int getOrupdate(vector > &grid, int m, int n) { if(m < 0 || n < 0) retu
2014-09-11 15:56:29
391
转载 Generate Parentheses,Rotate Image
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:"((()))", "(()
2014-09-09 21:14:50
325
原创 Plus One
class Solution {public: vector plusOne(vector &digits) { if(digits.size() == 0) return digits; int carry = 0; for(int i = digits.size()-1; i >=0 ; -- i) //如果使用的是size_t就是无符号的,如果减一了,那么就是一个大数
2014-09-09 20:59:50
302
原创 Pascal's Triangle , Pascal's Triangle II
Pascal's Triangle class Solution {public:vector > generate(int numRows) { vector > result; if(numRows <= 0) return result; vector row1(1,1); vector row2(2,1); if(numRows >= 1) re
2014-09-09 17:21:26
360
转载 Combination, subset
Subsetclass Solution {public: vector > subsets(vector &S) { vector > result; if(S.size() == 0) return result; sort(S.begin(), S.end()); int n = S.size(); vector each; resul
2014-08-20 16:02:00
386
转载 汉诺塔
现在想起来汉诺塔的算法就3个步骤:第一,把a上的n-1个盘通过c移动到b。第二,把a上的最下面的盘移到c。第三,因为n-1个盘全在b上了,所以把b当做a重复以上步骤就好了。所以算法看起来就简单多了。不过,思考过程还是很痛苦的,难以理解。递归中会保存数据的好处在这里又得到体现,太神奇了。汉诺塔代码如下:#include void mov
2014-08-16 21:35:08
384
转载 基于距离的计算方法
在分类聚类算法,推荐系统中,常要用到两个输入变量(通常是特征向量的形式)距离的计算,即相似性度量.不同相似性度量对于算法的结果,有些时候,差异很大.因此,有必要根据输入数据的特征,选择一种合适的相似性度量方法.令X=(x1,x2,..,xn)T,Y=(y1,y2,...yn)T为两个输入向量, 1.欧几里得距离(Euclidean distance)-Euclidean
2014-08-16 21:27:50
429
转载 Add two numbers-list,string
Add Two Numbers主要考虑两个链表相等位数的和,shengxia/* 提交多次才成功,主要是考虑,两个链表不一样长度 1. 12 7990,有数有进位 2. 1 99,无数有进位 5 5, */class Solution {public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2
2014-08-13 19:48:50
361
转载 sum 3- 4
3 Sumvector > threeSum(vector &num){ vector > result; if(num.size() < 3) return result; sort(num.begin(),num.end()); const int target = 0; auto last = num.end(); for(auto a = num.begin();
2014-08-13 16:15:48
380
转载 c++基础知识 7 -8 虚函数
7.用c++设计一个不能被继承的类在Java 中定义了关键字 final ,被 final 修饰的类不能被继承。但在 C++ 中没有final 这个关键字,要实现这个要求还是需要花费一些精力。 首先想到的是在 C++ 中,子类的构造函数会自动调用父类的构造函数。同样,子类的析构函数也会自动调用父类的析构函数。要想一个类不能被继承,我们只要把它的
2014-08-12 20:57:54
370
转载 笔试题目1
2. 假设函数f1的时间复杂度O(n),那么f1*f1的时间复杂度为()A. O(n)B. O(n*n)C. O(n*log(n))D. 以上都不对 这个题目我的思路是A,讨论后答案应该是D,因为f1的返回值不确定,如果是个数组当然复杂度就不同了。
2014-08-07 19:01:20
4129
转载 string 1
class Solution {public: bool isPalindrome(string s) { if(s.empty() ) return true; size_t i = 0; size_t j = 0; string s1 = ""; for(; i < s.size(); ++ i) { if('A'= s[i] ) { s1 +=
2014-08-04 21:28:22
322
转载 Permutation, next Permutation, Permutation sequence
class Solution {public: void nextPermutation(vector &num){ if(num.empty()) return; size_t j = num.size() - 1; size_t i = j - 1; while(i >= 0 && j > 0 && num[j] <= num[i]) { -- j; -- i;
2014-08-04 15:54:53
327
转载 c++ 基础知识 6
6.c++空类定义一个空的C++类,例如class Empty{}一个空的class在C++编译器处理过后就不再为空,编译器会自动地为我们声明一些member function,一般编译过去就相当于class Empty{public:Empty(); // 缺省构造函数Empty( const Empty& ); // 拷贝构造函数
2014-07-29 20:27:21
308
转载 c++基础知识 1-5
1.extern 声明1 基本解释:extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义。此外extern也可用来进行链接指定。 也就是说extern有两个作用,第一个,当它与"C"一起连用时,如: extern "C" void fun(int a, int b);则告诉编译器在编译fun这个函
2014-07-29 19:50:24
371
转载 BT 3 validate, unique, recover
Validate Binary Search Tree 浪费太多时间思考这个问题,结果知道了左孩子的右孩子必须比爷爷小,右孩子的左孩子必须比爷爷大,可是这么递归是超时的,实际上是归纳成先序遍历,递归判断,递归时传入两个参数,一个是左界,一个是右界,节点的值必须在两个界的中间,同时在判断做子树和右子树时更新左右界。class Solution {public: bool Va
2014-07-28 15:09:08
340
转载 BST : sorted list (array) to BST
Convert Sorted Array to Binary Search Tree
2014-07-23 10:29:12
349
转载 BT search 2 level order, Construct Binary Tree from Preorder and Inorder Traversal
Binary Tree Level Order Traversalclass Solution {public: vector > levelOrder(TreeNode *root) { vector > result; vector temp; queue myQueue; TreeNode* p
2014-07-22 21:00:18
531
转载 BST——depth, same,symmetric,path sum
bool check(TreeNode* left, TreeNode* right){ if(left == NULL && right == NULL) return true; if(left == NULL ||right == NULL) return false; if(left->val == right->val) return check(left->left
2014-07-22 20:56:11
427
转载 Remove
Remove Duplicates from Sorted Array class Solution {public: int removeDuplicates(int A[], int n) { if(n<=0) return 0; if(n==1) return 1; int i=0,j=1; //遍历一边又相同的就用后面的元素覆盖 whil
2014-07-21 18:14:45
355
转载 N queens
class Solution {public: bool isValid(vector& board, int n,int x, int y){ int i =0, j =0; for(i=0; i < x; ++ i) { if(board[i][y] == 'Q')//只可能是x之前的行,在同一列有相同的元素 return false; } for(i = 0; i
2014-07-20 17:00:09
311
转载 Populating Next Right Pointers in Each Node
/** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL)
2014-07-17 22:02:16
344
转载 cycle,reverse,rotate linked list
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool hasCycl
2014-07-17 21:37:30
291
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅