摘要: 概念全排列的生成算法有很多种,有递归遍例,也有循环移位法等等。C++/STL中定义的next_permutation和prev_permutation函数则是非常灵活且高效的一种方法,它被广泛的应用于为指定序列生成不同的排列。本文将详细的介绍prev_permutation函数的内部算法。按照STL... 阅读全文
posted @ 2014-06-20 13:20 穆穆兔兔 阅读(332) 评论(0) 推荐(0) 编辑
摘要: Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2014-06-20 09:58 穆穆兔兔 阅读(188) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord... 阅读全文
posted @ 2014-06-19 16:43 穆穆兔兔 阅读(237) 评论(0) 推荐(0) 编辑
摘要: STL中的每个算法都非常精妙, ForwardIterlower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, last)中的第一个大于等于值val的位置。 ForwardIter uppe... 阅读全文
posted @ 2014-06-18 17:44 穆穆兔兔 阅读(608) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of ... 阅读全文
posted @ 2014-06-18 15:50 穆穆兔兔 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m... 阅读全文
posted @ 2014-06-18 13:45 穆穆兔兔 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all uniquetriplets in the array which gives the sum of z... 阅读全文
posted @ 2014-06-18 10:27 穆穆兔兔 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 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 two nu... 阅读全文
posted @ 2014-06-17 17:14 穆穆兔兔 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 1.map, multimap, set, multisetg++ 中 map, multimap, set, multiset 由红黑树实现map: bits/stl_map.hmultimap: bits/stl_multimap.hset: bits/stl_set.hmultiset: bi... 阅读全文
posted @ 2014-06-17 15:02 穆穆兔兔 阅读(428) 评论(0) 推荐(0) 编辑
摘要: There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[... 阅读全文
posted @ 2014-06-16 16:32 穆穆兔兔 阅读(270) 评论(0) 推荐(0) 编辑