随笔分类 - 算法学习
一些常用的算法学习随笔
摘要:前言 【LeetCode 题解】系列传送门: " http://www.cnblogs.com/double win/category/573499.html " 题目链接 "54. Spiral Matrix" 题目描述 Given a matrix of m x n elements (m ro
阅读全文
摘要:前言 【LeetCode 题解】系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Say you have an array for which the ith element is th...
阅读全文
摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],...
阅读全文
摘要:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon...
阅读全文
摘要:The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie...
阅读全文
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings.题解: 寻找一组字符串的最长公共前缀。最简单的方法,用一个字符串记录当前最长的公共前缀,然后依次比较。时间复杂度: O(N). ...
阅读全文
摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo
阅读全文
摘要:前言 【LeetCode 题解】系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given an array with n objects colored red, white or blue, sort them so that objects of the same color a...
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thi
阅读全文
摘要:前言 【LeetCode 题解】系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Find the contiguous subarray within an array (containing at least one number) which has the largest sum...
阅读全文
摘要:前言 【LeetCode 题解】系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You h...
阅读全文
摘要:前言 【LeetCode 题解】系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numb...
阅读全文
摘要:Tips: 本文中所求的最小公倍数的对象都是正数!在求两个分数的最小公倍数之前,我们可以先来回顾一下如何求两个自然数的最小公倍数:1. 两个自然数的最小公倍数假设已知两个自然数a和b,求两者的最小公倍数 f(a,b):(1) 如果两个数互质,那么易知最小公倍数为f(a,b) = a*b;(2)如果两...
阅读全文
摘要:虽然TX的面试已经过去好几天了,然而惨痛的过程还历历在目。人生中第一次正式job面试就这么挂掉了。在于面试官的交流过程中,被问及了几个算法设计题,在今后几篇博文中,我一一总结与诸君分享。1.给定一个函数rand()能产生1到m之间的等概率随机数,产生1到n之间等概率的随机数? (为了简化问题,此处m小于n)当被问到这个问题的时候,LZ我首先的想法就是能不能通过一次Rand就可以把结果找到。然后这个想法就被瞬间推翻了。那么能否通过多次选取,然后组合呢? 答案是肯定的,然而悲剧的是,当时LZ的脑袋有点混乱了,想到了几个思路都不完备。这几天冷静下来之后,仔细想了想,现给出一个可行的方案,跟大家讨论讨
阅读全文
摘要:题目2 : Longest Repeated Sequence时间限制:10000ms单点时限:1000ms内存限制:256MB描述You are given a sequence of integers, A = a1, a2, ... an. A consecutive subsequence ...
阅读全文
摘要:n=412341213145111615610987n=512345161718196152425207142322218131211109简单的根据规律累加数字即可,注意几个边界条件的控制(向右 ,向下, 向左,向上的处理顺序)如果把(向右 ,向下, 向左,向上的处理顺序)作为一次处理逻辑,那么一共进行 n/2次循环即可。 1 #include 2 #include 3 using namespace std; 4 5 int a[100][100]={0}; 6 7 void fun(int n) 8 { 9 10 int c =1,i,j;11 fo...
阅读全文
摘要:题目出自面试宝典8.3.2题目描述: 输入n,求一个n*n的矩阵,规定矩阵沿45度线递增,形成一个zigzag数组(JPEG编码里去像素数据的排列顺序),请问如何用C++实现?例如: n=20123n=3015246378n=50156142471315381216219111720221018192324分析每个矩阵中上三角矩阵,可以看到上三角矩阵的元素都满足:s= i+j;a[i][j] = s*(s+1)/2 +( (s%2==0)?i:j);此外,下三角的矩阵的每个元素满足 a[i][j] + a[n-1-i][n-1-j] = N-1;根据上面的分析,可以得到如下的程序:#inclu
阅读全文
摘要:查找和排序是计算机应用中较为基础同时也很重要的两个组成成分。特别是当今网络如此盛行,Internet上充斥着各种各样的数据,图片,文本,音视频等,用户如何搜寻自己想要的数据,服务者如何及时有效的将用户的需求返回,都需要这些基础算法的帮助。在本人复习数据结构的时候,特意结合网上各位大牛的神贴,以及自己...
阅读全文
摘要:题目描述(转自:http://acm.hdu.edu.cn/showproblem.php?pid=2036)这是一道典型的求一个凸多边形面积的题,对于求解凸多边形面积,通常的思路就是将该多边形分割成多个可解的简单多边形,例如三角形或者矩形。对于连续和非连续的分布,分别可以采用积分法和三角形点分割的...
阅读全文

浙公网安备 33010602011771号