c**t 发帖数: 9197 | 1 MARCH U.S. T-Bonds
136 23/32--lifetime high
123 --Previous Month's high
120 2/32--second pivot point resistance
119 26/32--18-day moving average
119 18/32--first pivot point resistance
119 2/32--previous day's high
119 1/32--previous day's close
118 21/32--100-day moving average
118 17/32--pivot point
118 16/32--9-day moving average
118 1/32--4-day moving average
118 1/32--first pivot point support
117 17/32--previous day's low
117 --second pivot point support
116 16/32--previous month's low
110 |
|
l****z 发帖数: 29846 | 2 About Us
Subscribe
Contact Us
Donate
RSS
Illinois GOP: 'No Amount of Presidential Pivots and Speechmaking' Can Help
Our State's Unemployed
July 24, 2013 - 3:49 PM
By Craig Bannister
Subscribe to Craig Bannister RSS
Follow Craig Bannister on Twitter
"[N]o amount of presidential pivots and speechmaking will change the fact
that too many Illinoisans are out of work, Illinois' House Republicans
declared after President Obama spoke for more than an hour today in their
home state.
The ... 阅读全帖 |
|
N**********e 发帖数: 32 | 3 Is the Erlang qsort implementation the most concise one?
qsort([]) -> [];
qsort([Pivot|T]) ->
qsort([X || X <- T, X =< Pivot])
++ [Pivot] ++
qsort([X || X <- T, X > Pivot]). |
|
b***e 发帖数: 1419 | 4 我认为有O(n^2)的做法:
先把s1和s2转化成index表示:
tiger -> 12345
itreg -> 21543
第一个string总是正序的,第二个是乱序的。
那么问题转化成在s2里面找pivot index(在quicksort意义上的)。具体的说,一个
pivot index前面的数都<=这个index,它后面的数都>这个index。在上述例子中,
pivot index是1(counting from 0)。
找一个pivot index需要的时间是O(n)。找出所有的需要O(n^2)。 |
|
d*******e 发帖数: 24 | 5 方法和quicksort差不多。
在quicksort里,选择一个pivot value,完成partition,这时候有大于pivot value和
小于pivot value的两个序列,都需要递归的用quick sort排序。
如果要求第k大的数,只要判断一下该数在哪个序列里,然后对那一个序列再找第k'个
数就可以了。
该方法平均时间成本是O(n),如果选pivot时增加一些限制,可以保证最坏时间成本是O
(n)。 |
|
l*********8 发帖数: 4642 | 6 Given: n by m matrix A,
k
定义
int low[n]; // low[i]是在第i行查找的下限
int high[n]; // high[i]是在第i行查找的上限
low数组初始为全0, high全部是m.
取一个pivot (比如第n/2行的第k/n个元素), 在每行的low[i]和high[i]元素范围中找
该pivot对应的upper boundary,存为pos[i].
num = sum( pos[i] - low[i] | for all i) 就是比pivot小的element的数目。
if (num == k-1) {
return pivot;
} else if (num > k-1) {
// 把high数组(查找上限)update为pos数组的值。
// 在新的low,high范围内递归查找k-th smallest element
} else { // num < k-1
// 把low数组(查找下限)update为pos数组的值。
// 在新的low,high范围内递归查找... 阅读全帖 |
|
b*****y 发帖数: 547 | 7 今天看到了5个版本的,都说自己是hoare的
主要的疑惑在于, 那个pivot,有些版本,放在temp variable里,儿而有些版本,把
它移来移去的,有些版本是从左边第一个算pivot,有些是右边算pivot
到底哪个是hoare版本? 那个pivot把它放在temp里,最后在copy回update的位置,可
否?
谢谢 |
|
g*******s 发帖数: 2963 | 8 最土的On方法,就是设两个pivot代表中间的对称点. 这个点可以是个区间。基本就两
种情况比如 4311134,对称点就是111,或者43134对称点就是313,然后从这个对称区
间往两边扩展match,一旦发现不match就放弃当前pivot。
#include
#include
using namespace std;
vector findFristPal(vector& src)
{
int srcSize = src.size();
if (srcSize==0) return vector();
if (srcSize<=1) return vector(src[0],1);
bool isMatching = false;
int pivotLeft = 0;
int pivotRight = 0;
for (int i=1; i
{
if (!isMatchi... 阅读全帖 |
|
m**p 发帖数: 189 | 9 为什么泥?
class Solution {
public:
ListNode *partition(ListNode *head, int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode* dummy = new ListNode(-1);
ListNode* pivot = new ListNode(x);
ListNode* dummy_tail = dummy;
ListNode* pivot_tail = pivot;
ListNode* cur = head;
while (cur) {
if (cur->val < x) {
dummy_tail->next = cur;
dummy_tail = dummy_tail->next;
} else {
... 阅读全帖 |
|
t********e 发帖数: 12 | 10 持续partitioning,如果partition小于n/3,忽略;如果partition中的数字都相等,
则找到。
//return pivot position so that ary[begin...pivot]<=ary[pivot]
.end]
//or -1 if whole section are equal
static int Partition(int[] ary, int begin, int end)
{
//...
}
static bool FindItemOneThird(int[] ary, int begin, int end, out int item)
{
item = 0;
int pivotPos = Partition(ary, begin, end);
if (pivotPos == -1)
{
item = ary[begin];
return true;
}
//part1
if (pivotPos - begi... 阅读全帖 |
|
d****n 发帖数: 233 | 11 Share my solution:
class DLLNode {
public int value;
public int key;
public DLLNode left;
public DLLNode right;
public DLLNode(int k, int val)
{
key = k;
value = val;
left = this;
right = this;
}
public void detach()
{
right.left = left;
left.right = right;
}
public void addLeft(DLLNode node)
{
... 阅读全帖 |
|
r*****e 发帖数: 30 | 12 给定一个vector> v
其中string表示user id, int表示该user发帖数,找出发帖最多的k个用户
void kth(vector>& v, int begin, int end, int k){
if(end-begin+1
int i = begin, j = end;
pair pivot = v[end];
while(i < j){
while(i < j && v[i].second >= pivot.second) i++;
if(i < j) v[j--] = v[i];
while(i < j && v[j].second <= pivot.second) j--;
if(i < j) v[i++] = v[j];
}
v[i] = pivot;
if(i-begin+1 == k) return ;
if(i... 阅读全帖 |
|
S*******C 发帖数: 822 | 13 以下的O(n) time, O(1) space解法还能再简化吗?
Kth Largest Element
18%
Accepted
Find K-th largest element in an array.
Note
You can swap elements in the array
Example
In array [9,3,2,4,8], the 3rd largest element is 4
In array [1,2,3,4,5], the 1st largest element is 5, 2nd largest element is 4
, 3rd largest element is 3 and etc.
Challenge
O(n) time, O(1) space
class Solution {
public static void main(String args[]) {
Solution test = new Solution();
int[] a = { 5, 4, 1, 3, 2};
Arra... 阅读全帖 |
|
y*****e 发帖数: 712 | 14 很多家都有这题,假如有很多points,找出离原点最近的k个点。
做法就是建个size为k的heap, 建heap的complexity是o(k), 对后面n - k的点,还有
insert/pop operation的complexity是(n-k)log(k), 综合下来是nlogk
另外一种方法是任意去pivot, 每次call partition function, 把数组按放到pivot的
左边和右边,一直到pivot = k为止,直接return pivot左边的所有点。这种做法应该
是每次去掉一半的数组
n + n/2 + n/4 +.... = 2n也就是o(n),
应该是selection sort更好啊,为啥面试官总是让写heap? 是不是有其他的考量?比如
是streaming data或者数据量太大,不能一次完全放到array里? |
|
b*******w 发帖数: 56 | 15 def sort_by_quadratic_poly(nums, a, b, _):
pivot = -(b/(a*2.0))
index_right = bisect.bisect_left(nums, pivot)
sorted_by_quadratic_poly = []
index_left = index_right - 1
while index_left >=0 and index_right < len(nums):
if abs(nums[index_left] - pivot) <= abs(nums[index_right] - pivot):
sorted_by_quadratic_poly.append(nums[index_left])
index_left -= 1
else:
sorted_by_quadratic_poly.append(nums[index_right])
in... 阅读全帖 |
|
r*******u 发帖数: 143 | 16 会更努力的,请给我意见
如果要word file 请留下 email
Stock Research Trader
SPREWELL YU
Week ending: 01/07/2012
READING THE MARKET
The beginning of the New Year starts off with a strong demand from the big
investors. Things have turned much more positive as upside volume come back,
the pass few days every time when the market gap down only to turn positive
in the end of the session. The Nasdaq has reclaim its 50dma and 200dma that
’s a very constructive sign that big investors are back to the market,due to
strong... 阅读全帖 |
|
l**********y 发帖数: 2050 | 17 发信人: riseofyou (You), 信区: Stock
标 题: 小弟第一次写股评报告,请大家多多包涵 for week 1/7/12
发信站: BBS 未名空间站 (Sat Jan 7 12:06:02 2012, 美东)
会更努力的,请给我意见
如果要word file 请留下 email
Stock Research Trader
SPREWELL YU
Week ending: 01/07/2012
READING THE MARKET
The beginning of the New Year starts off with a strong demand from the big
investors. Things have turned much more positive as upside volume come back,
the pass few days every time when the market gap down only to turn positive
in the end of the session. The Nasdaq has... 阅读全帖 |
|
r*******u 发帖数: 143 | 18 Stock Research Trader
current holding- AH, TIBX, LNKD, FTNT, SPPI, INVN, VPHM
Sprewell Yu
Week ending: 01/21/2012
READING THE MARKET
The scent of game on long side has stated over the last two reports. The
NYSE has gone above 200 day line while Nasdaq broke out of a consolidation
with confirmation from leading stocks. On Tuesday the market gap up from
strong GDP Data from China, the market has gap up in the morning has pulled
back by Citigroup miss earning, While on Wednesday plenty of stock has... 阅读全帖 |
|
d****0 发帖数: 26 | 19 跟进之前的帖子:http://www.mitbbs.com/article_t/Stock/36416051.html
除了对大盘SPX2015数据进行总结之外,还新涵盖了:
AAPL beta-0.87
BAC beta-1.79
MS beta-2.38
数据如下:
1/2/2015-10/23/2015,共205个交易日。
AAPL beta 0.87
Close Price:
191 Day > S3, 93%
177 Day > S2, 86%
155 Day > S1, 76%
111 Day > P , 54%
94 Day < P , 46%
145 Day < R1, 71%
179 Day < R2, 87%
191 Day < R3, 93%
Lowest Price:
183 Day > S3, 89%
159 Day > S2, 78%
112 Day > S1, 55%
Highest Price:
109 Day < R1, 53%
163 Day < R2, 80%
188 Day < R3, 92%
BAC beta ... 阅读全帖 |
|
p*********e 发帖数: 32207 | 20 你是说最后出手时先抬了pivot foot?
规则上运球是要先运后抬pivot foot,传球或者投篮的话先抬pivot foot也可以
只要pivot foot再次落地前球出手就好.
不过国内很多裁判都是两个混着吹,真被吹了也没法较真
所以通常不鼓励这么练:) |
|
T***c 发帖数: 17256 | 21 如果我两脚落地后都不懂,尽管先后落地,仍然可以选择哪一只是pivot,这个没争议。
有争议的就是后面这部分,
照你这找到这个规则,落地后两只脚无论选哪一只,比如我选左脚,那我无论右脚怎么
动无所谓,哪怕迈出去一大步,然后右脚站定不动,左脚抬起来,然后左脚在空中没落
地之前我出手或者传球都不走走步,实际上就是于停球后可以再走2步,第二步落地前
出手就行。
我一直以为,右脚无论怎么动都行,但不能右脚站定后,再把pivot左脚抬起来然后再
出手--必须在pivot左脚离地之前就出手。
以前还专门问过一个半专业的,他的意见也是“必须在pivot左脚离地那一瞬间之前就
出手”这个。
但NBA里边这种情况吹了不吹的都有,甚至跟动作连贯性都没关系:当年老穆的僵尸慢
三步不晓得大家还记得不,毫无连贯性可言但基本没被吹过,就是利用的这个规则。
至于fifa,我的印象是吹的,不过一时举不出啥例子来。 |
|
g****t 发帖数: 31659 | 22 d这个规则不适用.因为他换了pivot foot.
"
c. In starting a dribble after (1) receiving the ball while standing still
, or (2) coming to a
legal stop, the ball must be out of the player’s hand before the pivot foot
is raised off the
floor.
d. If a player, with the ball in his possession, raises his pivot foot off
the floor, he must
pass or shoot before his pivot foot returns to the floor. If he drops the
ball while in the air, he
may not be the first to touch the ball.
"
你看一下d |
|
s*******u 发帖数: 1855 | 23 这个为什么是合法的? 难道走步不是永远用pivot定义吗? 难道走步描述的改变取决于
pivot定义的改变吗?
这个先迈步再跳步,无论如何改变pivot定义,总是pivot两次落地了.为什么能够合法? |
|
H*******o 发帖数: 504 | 24 travel occurs when you LIFT your pivot (and not shoot/pass), not when you
LAND your pivot foot "the second time". But this is really not the point for
LBJ's case. Basketball rules have clear statements on which foot can be a
pivot foot for a given circumstance. For LBJ's case, NEITHER foot can be the
pivot after the jump step. So he can only shoot/pass, which was what he did.
So no problem, by any standard. |
|
f******y 发帖数: 830 | 25 情况如下:
中国人pick up,一个四十加大哥上篮,常规步法,最后左脚踏步,同时发现正前方有防
守队员,他居然hold 住了,就是没跳起来,然后右脚悬空达到三秒以上。最后直到找
到队友把球传了出去。
我不淡定了,这不是明显的走步吗?pivot foot虽然没落地,但是“non-pivot" foot
站立持球三秒,不应该算是事实上的pivot foot 吗? 这就是在没有运球的情况下,交
换pivot foot, 当然是走步了。
请斑竹帮忙引个规则,或许我的理解有误?
另外,好多人用类似的动作,就是上篮起跳脚故意延迟起跳来晃防守(慢步上篮,最后
一步踩地上弹起特别慢),但是比较连贯。这个持球时间上如果正式比赛有界定吗?
pick-up 就算了,没人计较。 |
|
r***v 发帖数: 12658 | 26 在FIBA下也是不合理的
但问题在于需要在这么短的时间内做到:
1. 非pivot落地
2. 抬pivot,重心转移到非pivot
3. 非pivot起跳,球出手
其实是挺难的,你试一下就知道了
但如果改成双脚同时起跳就容易多了,或者是差不多时间的一前一后起跳(就是视频里
的),而且闪出来的空间其实也差不多 |
|
p*********e 发帖数: 32207 | 27 抱歉我前面没说清楚
规则里面是说,可以抬起pivot foot甚至jump off pivot foot,但是:
While moving:
. To pass or shoot for a field goal, the player may jump off a pivot foot
and land on one foot or both feet simultaneously. After that, one or both
feet may be lifted from the floor but neither may be returned to the floor
before the ball is released from the hand(s).
也即是说如果非pivot脚起跳,一样是在这只脚落地前要完成投篮或者传球 |
|
s*****c 发帖数: 753 | 28
Did you do it correctly?
When you catch the ball in air and land one feet, you havn't establish pivot
yet, when your second feet land, that is pivot, this pivot feet can be
lifted but not landed before you shoot.
So if you land left feet first after you catch the ball in air, the
following is the sequence:
Left -> right (pivot feet) -> left -> shoot |
|
g****t 发帖数: 31659 | 29 规定时刻
T1=双手持球的时刻。
如果T1是在空中发生的。那么T1之后,球出手之前,脚可以落地三次。
只要搞对就行了?
catch the ball->left->right->left?
或者你是说
left->catch the ball->right->left?
Did you do it correctly?
When you catch the ball in air and land one feet, you havn't establish pivot
yet, when your second feet land, that is pivot, this pivot feet can be
lifted but not landed before you shoot.
So if you land left feet first after you catch the ball in air, the
following is the sequence:
Left -> right (pivot feet) -> left -> shoot |
|
|
m*****r 发帖数: 1240 | 31 我理解你的思路
你是要硬扣 jump off a pivot foot 这句话来证明:pivot foot必须最后或者和非中
枢脚同时离地 (不允许中枢脚先离地,非中枢脚后离地)
我个人感觉你的这个解释有点牵强。 如果规则是个意思的话,完全可以加一句准确
的描述来 禁止 中枢脚先离地。
当然,你也可以说,规则如果支持 中枢脚先离地的话,也可以加一句 更准确的描述来
允许 中枢脚先离地; 不过貌似https://www.youtube.com/watch?v=aiIkCBe8EK4,
这个视频里的附加解释说明了 jump off a pivot foot 等同于 lift a pivot foot,
来间接的补充说明 允许 中枢脚先离地。 另外 https://bbs.hupu.com/18320644.html
这个帖子里也有些补充的证据。
说实话,虽然我支持 中枢脚先离地 (为了和三步上篮(行进间的动作)保持某种一致
性), 但我认为这个的确是规则有点模糊的地方(可以说的更清楚)。 我看过大梦
还有乔丹的视频集锦,他们确实大部分是 最后双脚同时起跳,很少很少 中枢脚先离... 阅读全帖 |
|
O****e 发帖数: 3290 | 32 I am not sure these are accurate statements.
My understanding: pivot is mostly or is supposed to be the result of
steering which is initiated by the skier. But, it can be the result of
anything a crazy skier can do.
A skier can achieve steering by simply engaging the edge or by actively
turning his feet. Normally, pivot is the result of turning feet. Engaging
edge in general will not lead to pivot. So, it is correct to say steering
may or may not lead to pivot. |
|
l*****r 发帖数: 91 | 33 今天private继续了几个open的figure。 难度的确是有点令人吃不消,而且男老师不在
,女老师只是把动作给我说说就让我和partner一起来,真是跳的踉踉跄跄。
问题还是pivots, open的figure里面难的地方全都是pivots!!! 我现在一到pivots
就有点紧张。
不过可喜可贺的是前些日子一直跳不好的natual spin -> natual pivots -> running
lock,今天居然比较smooth, 让我和partner着实happy了一下。呵呵 |
|
n*w 发帖数: 3393 | 34 C#:
public static IEnumerable QSLinq(IEnumerable items)
{
if (items.Count() <= 1) return items;
var pivot = items.First();
return QSLinq(item.Where(i=>i
.Concat(QSLinq(item.Where(i=>i==pivot))
.Concat(QSLinq(item.Where(i=>i>pivot));
} |
|
n*w 发帖数: 3393 | 35 C#:
public static IEnumerable QSLinq(IEnumerable items)
{
if (items.Count() <= 1) return items;
var pivot = items.First();
return QSLinq(item.Where(i=>i
.Concat(QSLinq(item.Where(i=>i==pivot))
.Concat(QSLinq(item.Where(i=>i>pivot));
} |
|
m*******s 发帖数: 469 | 36 I have a new position in Greensboro, NC. It’s for Novartis Animal Health
– a very stable company that is working on some interesting projects,
many in the area of vaccines. Ideally they would like to hire at the
Senior Biostatistician level and they are looking for a MS with 3 years
in industry or a PhD with 1. I thought I would circulate this around to
see if you knew anyone who might be interested in such a position –
please feel free to pass it along. Thank you so much! Here is the
official j... 阅读全帖 |
|
|
发帖数: 1 | 38 【IT求职成功分享视频】
https://youtube.com/playlist?list=PLRMhRP6Z9GjQMa3LmGMOgoYfuzErGOifZ
【微软Dynamic CRM 项目求职和证书】
OTO(线下线上授课)
最权威的CRM专家
最火爆炙热的职场和市场需求
最精品高效的IT技术
最有效的IT求职培训
知识传递,面试,求职一包到底,100%获取微软CRM 认证证书
云,移动和大数据三大技术趋势以及社交化的发展正在构建新型的IT生态环境,也进一
步将个人与企业紧密地联系起来,使得企业运营和决策能够及时反应来自市场的需求,
让客户满意度最大化,也让企业本身经济效益最大化。这一切都与CRM的广泛成熟运用
密不可分。何为CRM? CRM是Customer Relationship Management的缩写,也就是客户
关系管理。这是一套集销售管理、市场管理、服务管理、敏捷市场反应以及客户商机数
据分析挖掘的平台和技术。
微软的基于云技术的Dynamic CRM平台是目前CRM解
决方案的领导者,被广泛地应用于各个行业如银行、金融、证券、制造业、政府、医疗
... 阅读全帖 |
|
|
x******g 发帖数: 33885 | 40 民主党就是个反华的政党。
Obama Doctrine: China is the New ‘Enemy Image’
After almost two decades of neglect of its interests in East Asia, in 2011,
the Obama Administration announced that the US would make “a strategic
pivot” in its foreign policy to focus its military and political attention
on the Asia-Pacific, particularly Southeast Asia, that is, China. The term
“strategic pivot” is a page out of the classic textbook from the father of
British geopolitics, Sir Halford Mackinder, who spoke at various tim... 阅读全帖 |
|
R****a 发帖数: 6858 | 41 从而便于在中东北非发动针对美元的代理人战争.
The Russia-China Axis Grows
March 14, 2013 By Ariel Cohen 16 Comments
34 Print This Post
China’s new president Xi Jinping will make his first official foreign visit
later this month. He will visit Russia, in a trip Chinese sources say “
will improve relations and cement strategic partnership.”
Washington should pay attention to the strengthening ties between Moscow and
Beijing. These giant neighbors have the longest shared land border in the
world, and trade between the tw... 阅读全帖 |
|
b********n 发帖数: 38600 | 42 http://www.counterpunch.org/2014/12/01/defending-dollar-imperia
“The Fed’s ‘need’ to take on an even more active role as foreigners
further slow the purchases of our paper is to put the pedal to the metal on
the currency debasement race now being run in the developed world — a race
which is speeding us all toward the end of the present currency regime.”
– Stephanie Pomboy, MacroMavens
“No matter what our Western counterparts tell us, we can see what’s going
on. NATO is blatantly building up its ... 阅读全帖 |
|
b********n 发帖数: 38600 | 43 http://www.tomdispatch.com/blog/176003/
Delusionary Thinking in Washington
The Desperate Plight of a Declining Superpower
By Michael T. Klare
Take a look around the world and it’s hard not to conclude that the United
States is a superpower in decline. Whether in Europe, Asia, or the Middle
East, aspiring powers are flexing their muscles, ignoring Washington’s
dictates, or actively combating them. Russia refuses to curtail its support
for armed separatists in Ukraine; China refuses to abandon its... 阅读全帖 |
|
c*********r 发帖数: 19468 | 44 这算哪门子细节?你就算一砣实心的铝碇,1m^3,也才2.7吨,一对pivot总成能多重?
最早的变后掠翼验证机X-5的pivot总成也只有370磅而已
引擎推力都能给个数,pivot的重量级反倒保密?你自己不觉得搞笑吗? |
|
r***8 发帖数: 86 | 45 大家看这样解法对不对
请把其中的问 题找出来:)
哪位高手能否说出这样找的复杂度是多少
从最短的那个序列中每个数开试
试出有S 个序列,取其中最短DISTANCE的序列既为找的结果
在试的时候,可否这样找
先以刚取出的数为pivot
FOR EACH 剩余的序列
找与pivot 最近的数,
加入已找到的序列,
pivot 调整 为已找到数最大和最小的均值。 |
|
d**e 发帖数: 6098 | 46 小于pivot的放左右,大于pivot的放右边,等于pivot的放中间
谁有比较简洁的code?
我写了很久还是非常烦琐。
谢谢。
另外看见另外一道类似的算法,应该是同一个问题:一个数组,把数字放左边,小写字
母放中间,大写字母放右边。 |
|
d**e 发帖数: 6098 | 47 谢谢。真的很简洁。
void three_way_partition(int array[], int i, int j)
{
int k = i;
int pivot = array[j];
while(i < j)
{
if(array[i] == pivot)
i++;
else if(array[i] < pivot)
{
swap(array[i], array[k]);
k++;
i++;
}
else
{
swap(array[i], array[j]);
j--;
}
}
} |
|
b***e 发帖数: 1419 | 48 这个不用联合,就是二分法。找一个pivot, split一下:
pre_array, pivot, post_array
如果
1. pre_array.length < pivot,那么空子在前面,recursion on pre_array。
2. 否则空子在后面,recursion on post_array。
这招不能直接搞重复的情形。如果哦有重复,可以两招一起用:
2. 如果ihasleetcode_method(pre_array)找到的空子,return; otherwise,
recursion on (post_array).
这个不丢信息,而且期望为O(n). |
|
g*****k 发帖数: 623 | 49 if there are negative numbers, does this work?
pick a random pivot then put it to the right position,
calculate mean for left and right subarray, if left > right, pick another
pivot in the left subarray, if left < right, pick another pivot in the right
subarray, until it is equal or return the smaller difference one.
and it seems my previous post doesn't work for all positive numbers neither.
I can't prove its correctness and find a couter example.
Hope some big cow chips in |
|
s***h 发帖数: 662 | 50
就是你quicksort不是选一个pivot吗, 然后partition,
这个pivot的最后位置比如说是某个k, 那么它就是第k大(小)的元素.
这个partition就是O(n)啊. 当然这个位置未必是你找的,那么你再
继续在这个pivot的一边partition下去,最后总能找到你要的那个位置.
假定总是平分, n + n/2 + n/4 + ... = 2n. 所以线性时间.
不过我早上犯糊涂了. 那根本不是n*k, 那就是n, 因为你找到第k大的,
它右边的partition里面就是1-(k-1)大的, 所以那个k可以去掉. 但是
奇怪的是他也没有反应过来, 可能他猛一看,也觉得每个都n, 那么k个
就乘k也对. :-) |
|