Leetcode 15 3sum
摘要:1.题目要求Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:...
阅读全文
Leetcode 3 Longest Substring Without Repeating Characters
摘要:1.题目要求Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating lett...
阅读全文
Leetcode 4 Median of Two Sorted Arrays
摘要:1.题目要求There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity shou...
阅读全文
Leetcode 1 Two Sum
摘要:1.题目要求Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the ...
阅读全文
内联函数与宏
摘要:因为函数的调用必须要将程序执行的顺序转移到函数所存放在内存中的某个地址,将函数的程序内容执行完后,再返回到转去执行该函数前的地方。这种转移操作要求在转去执行前要保存现场并记忆执行的地址,转回后要恢复现场,并按原来保存地址继续执行。因此,函数调用要有一定的时间和空间方面的开销,虽然函数调用开销是很小的...
阅读全文
面试算法题:16个数,最多用20次比较,找出第二大的数?
摘要:这道题最笨的方法就是先从16个数中选出最大的数,然后再从剩下的15个数中选出最大数就可得到答案,因此,需要15+14=29次比较。既然这道题要求在20次比较之内就能找出第二大的数,那我们就想能简单的方法。假设16个数中最大的是A,第二大的是B。首先将16个数两两进行比较,较大者胜出,然后再在胜出者中...
阅读全文
windows中通过bat批处理打开exe文件
摘要:1、想要运行的程序:C:\Program Files\Windows Media Player\wmplayer.exeC:\Program Files\Haihaisoft Universal Player\hmplayer.exe2、在桌面上,“新建文本文档.txt”,方法是:在桌面上右键,新建...
阅读全文
动态规划求两个序列的最长公共子序列
摘要:摘录:http://blog.chinaunix.net/uid-26548237-id-3374211.html1、序列str1和序列str2 ·长度分别为m和n; ·创建1个二维数组L[m.n]; ·初始化L数组内容为0 ·m和n分别从0开始,m++,n++循环: - 如果str1[m]...
阅读全文
HDU 5182
摘要:#include #include #include using namespace std;/************************************************************************//* HDU 5182题 http://acm.hdu.e...
阅读全文
利用动态规划求矩阵中和最大的子矩阵
摘要:题目一:给定一个整型数组,数组中有正有负,求最大连续子序列的和。解法:利用动态规划的思想。设f(n)表示以a[n]为子序列最后一个元素的最大和,则可以有下面的规则:(1)当f(n-1)0时,f(n)=f(n-1)+a[n]。用一个nGreatestNum来记录最大值,每次与f(n)进行比较,不断更新...
阅读全文