E-COM-NET
首页
在线工具
Layui镜像站
SUI文档
联系我们
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
每日算法
每日算法
之三十六:Permutations && Permutations II
Givenacollectionofnumbers,returnallpossiblepermutations.Forexample,[1,2,3] havethefollowingpermutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],and [3,2,1].将第0个字符和从第0开始的每个字符进行交换,对于交换后的结果,再从第1个字符开始
yapian8
·
2014-06-25 20:00
每日算法
之三十五:Wildcard Matching
模式匹配的实现,'?'代表单一字符,'*'代表任意多的字符,写代码实现两个字符串是否匹配。Implementwildcardpatternmatchingwithsupportfor '?' and '*'.、'?'Matchesanysinglecharacter. '*'Matchesanysequenceofcharacters(includingtheemptysequence). Th
yapian8
·
2014-06-18 09:00
模式匹配
每日算法
之三十四:Multiply Strings
大数相乘,分别都是用字符串表示的两个大数,求相乘之后的结果表示。首先我们应该考虑一下测试用例会有哪些,先准备测试用例对防御性编程会有比较大的帮助,能够考虑一些极端情况。有以下几种用例:1)"0","0" 2)"0","879127346783"其中一个是零3)"as234","123343" 存在非法字符4)"000000000000001234","2546" 存在零前缀,有冗余计算大概就这么多
yapian8
·
2014-06-15 16:00
大数相乘
大数相加
每日算法
之三十三:Trapping Rain Water
这是一个很有意思的问题,求解最大容积问题,值得动脑筋想一想。原题如下:Given n non-negativeintegersrepresentinganelevationmapwherethewidthofeachbaris1,computehowmuchwateritisabletotrapafterraining.Forexample, Given [0,1,0,2,1,0,1,3,2,1,
yapian8
·
2014-06-13 22:00
每日算法
之三十二:First Missing Positive
Givenanunsortedintegerarray,findthefirstmissingpositiveinteger.Forexample,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Youralgorithmshouldrunin O(n)timeandusesconstantspace.classSolution{ public: in
yapian8
·
2014-06-10 21:00
每日算法
之三十一:Combination Sum
给定一个整数序列,求解一个子序列,子序列之和等于给定目标值。子序列满足以下条件:1)子序列是有序的2)子序列的元素个数不限,可以是给定元素的重复元素。3)结果中的子序列是唯一的原题描述如下:Givenasetofcandidatenumbers(C)andatargetnumber(T),findalluniquecombinationsin C wherethecandidatenumberss
yapian8
·
2014-06-08 22:00
每日算法
之三十:Valid Sudoku (九宫格)
DetermineifaSudokuisvalid,accordingto: SudokuPuzzles-TheRules.TheSudokuboardcouldbepartiallyfilled,whereemptycellsarefilledwiththecharacter '.'.Apartiallyfilledsudokuwhichisvalid.Note:AvalidSudokuboar
yapian8
·
2014-06-06 21:00
九宫格
每日算法
之二十九:Search in Rotated Sorted Array
在一个经过旋转后的有序数组中查找一个目标元素。Supposeasortedarrayisrotatedatsomepivotunknowntoyoubeforehand.(i.e., 0124567 mightbecome 4567012).Youaregivenatargetvaluetosearch.Iffoundinthearrayreturnitsindex,otherwisereturn
yapian8
·
2014-06-04 22:00
每日算法
之二十八:Longest Valid Parentheses
Givenastringcontainingjustthecharacters '(' and ')',findthelengthofthelongestvalid(well-formed)parenthesessubstring.For "(()",thelongestvalidparenthesessubstringis "()",whichhaslength=2.Anotherexample
yapian8
·
2014-06-03 11:00
每日算法
之二十七:Next Permutation(下一个字典序)
求解的是下一个字典序,下面给出两个不同理解方式的字典序的定义:可以直接看第二种定义,但是算法还是用官方的定义来求解。1)官方定义:字典序法是由当前序列直接生成下一个排列的算法:排列定义:P=P1P2```Pn 第一步:求满足关系式P(k-1)1243->1324->1342->1423->1432->2134->2143->2314->2341->2413->2431->3124->3142->
yapian8
·
2014-06-02 15:00
迭代器
每日算法
之二十六:Substring with Concatenation of All Words
变相的字符串匹配给定一个字符串,然后再给定一组相同长度的单词列表,要求在字符串中查找满足以下条件的起始位置:1)从这个位置开始包含单词列表中所有的单词,且每个单词仅且必须出现一次。2)在出现的过程中不能出现其他的干扰单词。3)出现的位置可能有多个。4)单词的出现顺序不做要求。下面是一个例子:S:"barfoothefoobarman"L:"foo","bar"位置0是出现位置,;两个单词均出现仅出
yapian8
·
2014-06-02 10:00
每日算法
之二十五:Divide Two Integers
Dividetwointegerswithoutusingmultiplication,divisionandmodoperator.不使用乘法、除法和求模运算求两个数相除。classSolution{ public: longlonginternalDivide(unsignedlonglongdividend,unsignedlonglongdivisor) { if(dividenddivi
yapian8
·
2014-06-01 15:00
每日算法
之十七:Letter Combinations of a Phone Number
Givenadigitstring,returnallpossiblelettercombinationsthatthenumbercouldrepresent.Amappingofdigittoletters(justlikeonthetelephonebuttons)isgivenbelow.Input:Digitstring"23" Output:["ad","ae","af","bd","
yapian8
·
2014-06-01 14:00
每日算法
之二十四:Implement strStr()
ImplementstrStr().Returnsapointertothefirstoccurrenceofneedleinhaystack,or null ifneedleisnotpartofhaystack.下面是两种方法:(1)classSolution{ public: char*strStr(char*haystack,char*needle){ if(needle==NULL||*
yapian8
·
2014-06-01 09:00
查找
每日算法
之二十三:Reverse Nodes in k-Group
Givenalinkedlist,reversethenodesofalinkedlist k atatimeandreturnitsmodifiedlist.Ifthenumberofnodesisnotamultipleof k thenleft-outnodesintheendshouldremainasitis.Youmaynotalterthevaluesinthenodes,onlyn
yapian8
·
2014-05-31 11:00
链表
每日算法
之二十二:Swap Nodes in Pairs
Givenalinkedlist,swapeverytwoadjacentnodesandreturnitshead.Forexample,Given 1->2->3->4,youshouldreturnthelistas 2->1->4->3.Youralgorithmshoulduseonlyconstantspace.Youmay not modifythevaluesinthelist,o
yapian8
·
2014-05-30 20:00
链表
每日算法
之二十一:Merge k Sorted Lists
Merge k sortedlinkedlistsandreturnitasonesortedlist.Analyzeanddescribeitscomplexity.函数原型如下:ListNode*mergeKLists(vector&lists) 给定一个向量(vector),存储的是每个链表的头指针。要求是把这k个有序链表合并成一个有序的链表输出。我们可以采用分治法进行处理,分治法在算法结构
yapian8
·
2014-05-28 11:00
链表
每日算法
之二十:Generate Parentheses
Given n pairsofparentheses,writeafunctiontogenerateallcombinationsofwell-formedparentheses.Forexample,given n =3,asolutionsetis:"((()))","(()())","(())()","()(())","()()()"给出数字n,求出所有合法的表达式。我们用二叉树形象的表示
yapian8
·
2014-05-26 21:00
递归
每日算法
之十九:Valid Parentheses
这个就是查看括号是否是匹配的。使用STL中的stack是容易实现的。代码如下:Givenastringcontainingjustthecharacters '(', ')', '{', '}', '[' and ']',determineiftheinputstringisvalid.Thebracketsmustcloseinthecorrectorder, "()" and "()[]{}"
yapian8
·
2014-05-26 15:00
括号匹配
每日算法
之十八: Remove Nth Node From End of List
Givenalinkedlist,removethe nth nodefromtheendoflistandreturnitshead.Forexample,Givenlinkedlist:1->2->3->4->5,andn=2. Afterremovingthesecondnodefromtheend,thelinkedlistbecomes1->2->3->5. Note:Given n
yapian8
·
2014-05-25 22:00
链表
每日算法
之十六:4sum
Givenanarray S of n integers,arethereelements a, b, c,and d in S suchthat a + b + c + d =target?Findalluniquequadrupletsinthearraywhichgivesthesumoftarget.Note:Elementsinaquadruplet(a,b,c,d)mustbeinno
yapian8
·
2014-05-25 21:00
4sum
每日算法
之十五:threesumClosset
Givenanarray S of n integers,findthreeintegersin S suchthatthesumisclosesttoagivennumber,target.Returnthesumofthethreeintegers.Youmayassumethateachinputwouldhaveexactlyonesolution.Forexample,givenarra
yapian8
·
2014-05-23 21:00
近似三元组
每日算法
之十四:3Sum
Givenanarray S of n integers,arethereelements a, b, c in S suchthat a + b + c =0?Findalluniquetripletsinthearraywhichgivesthesumofzero.Note:Elementsinatriplet(a,b,c)mustbeinnon-descendingorder.(ie, a
yapian8
·
2014-05-23 11:00
3Sum
三元组为零
每日算法
之十三:Longest Common Prefix
Writeafunctiontofindthelongestcommonprefixstringamongstanarrayofstrings.求解多条字符串的最长公共前缀。classSolution{public:stringlongestCommonPrefix(vector&strs){stringresult;intlen=strs.size();inti,j;if(len==0)retu
吴正伟的博客
·
2014-05-21 11:10
leetcode
算法
每日算法
之十三:Longest Common Prefix
Writeafunctiontofindthelongestcommonprefixstringamongstanarrayofstrings.求解多条字符串的最长公共前缀。classSolution{public: stringlongestCommonPrefix(vector&strs){ stringresult; intlen=strs.size(); inti,j;
yapian8
·
2014-05-21 11:00
算法
每日算法
之十二:Roman to Integer
Givenaromannumeral,convertittoaninteger.Inputisguaranteedtobewithintherangefrom1to3999.classSolution{ public: inttoNUm(charch) { switch(ch) { case'I':return1; case'V':return5; case'X':return10; case'L
yapian8
·
2014-05-19 22:00
算法
每日算法
之十一:Integer to Roman
题目:Givenaninteger,convertittoaromannumeral.Inputisguaranteedtobewithintherangefrom1to3999.罗马表示方式如下:I=1;V=5;X=10;L=50;C=100;D=500;M=1000;其中每两个阶段的之间有一个减法的表示,比如900=CM,C写在M前面表示M-C。范围给到3999,感觉情况不多直接打表其实更快,
yapian8
·
2014-05-18 22:00
罗马数字转换
每日算法
之十:Container With Most Water
Given n non-negativeintegers a1, a2,..., an,whereeachrepresentsapointatcoordinate(i, ai). n verticallinesaredrawnsuchthatthetwoendpointsofline i isat(i, ai)and(i,0).Findtwolines,whichtogetherwithx-axi
yapian8
·
2014-05-18 21:00
遍历
每日算法
之九:Regular Expression Matching
classSolution{ public: boolisMatch(constchar*s,constchar*p){ //StarttypingyourC/C++solutionbelow //DONOTwriteintmain()function if(0==*p)return0==*s; if(*(p+1)!='*') { if(*p==*s||(*p)=='.'&&(*s)!=0)
yapian8
·
2014-05-16 22:00
C++
每日算法
之八:String to Integer (atoi) 及溢出分析
Implement atoi toconvertastringtoaninteger. Hint: Carefullyconsiderallpossibleinputcases.Ifyouwantachallenge,pleasedonotseebelowandaskyourselfwhatarethepossibleinputcases.Notes: Itisintendedforthispro
yapian8
·
2014-05-10 16:00
溢出
atoi
每日算法
之七:Reverse Integer
Reversedigitsofaninteger.Example1: x=123,return321Example2: x=-123,return-321反转整形数字,使用取余取整循环即可,但是实际要考察的应该是对可能输入的考虑是否全面:1)是否为零2)如果是1200,翻转后是0021还是213)如果是2*********7(INT_MAX),翻转后是7*********2是越界的,不能保存,应该
yapian8
·
2014-05-08 11:00
反转整形数字
每日算法
之五:Longest Palindromic Substring
题目描述:Givenastring S,findthelongestpalindromicsubstringin S.Youmayassumethatthemaximumlengthof S is1000,andthereexistsoneuniquelongestpalindromicsubstring.求解的是字符串中最长的回文子串,跟求解最长子串不一样,不可以再使用哈希表来标记字符上次出现的
yapian8
·
2014-04-30 20:00
回文子串
每日算法
之三:Longest Substring Without Repeating Characters
题目要求:Givenastring,findthelengthofthelongestsubstringwithoutrepeatingcharacters.Forexample,thelongestsubstringwithoutrepeatinglettersfor"abcabcbb"is"abc",whichthelengthis3.For"bbbbb"thelongestsubstring
yapian8
·
2014-04-02 11:00
算法
每日算法
之二:Median of Two Sorted Arrays
题目要求如下:TherearetwosortedarraysAandBofsizemandnrespectively.Findthemedianofthetwosortedarrays.TheoverallruntimecomplexityshouldbeO(log(m+n)).给出两个有序数组,求解数组合集中的中位数。求解中位数是求第k大个数的特例,所以我们下面的讨论以求解第k大个数为例子讨论。
yapian8
·
2014-03-29 16:00
算法
中位数
每日算法
之一:Two Sum
题目要求如下:Givenanarrayofintegers,findtwonumberssuchthattheyadduptoaspecifictargetnumber.ThefunctiontwoSumshouldreturnindicesofthetwonumberssuchthattheyadduptothetarget,whereindex1mustbelessthanindex2.Ple
yapian8
·
2014-03-29 15:00
算法
排序
每日算法
之大数加法
#include"stdio.h" #include"math.h" #include"string.h" #include #include usingnamespacestd; voidreverse(chars[],intlen) { inti=0; intswap; while(ilen2?(len1+1):(len2+1); swap=(int*)malloc(sizeof(int)*n
lskyne
·
2013-02-23 12:00
C语言8大经典排序算法
【
每日算法
】C语言8大经典排序算法(2)接上文--->【
每日算法
】C语言8大经典排序算法(1)二、插入类排序插入排序(InsertionSort)的基本思想是:每次将一个待排序的记录,按其关键字大小插入到前面已经排好序的子文件中的适当位置
·
2013-01-25 16:00
希尔排序
排序算法
每日算法
之四:Add Two Numbers
题目要求如下:Youaregiventwolinkedlistsrepresentingtwonon-negativenumbers.Thedigitsarestoredinreverseorderandeachoftheirnodescontainasingledigit.Addthetwonumbersandreturnitasalinkedlist.Input: (2->4->3)+(5->
yapian8
·
2012-03-02 11:00
C++
算法
面试
上一页
4
5
6
7
8
9
10
11
下一页
按字母分类:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
其他