Redian新闻
>
MS Brings Cortana Enabled Cards On Bing.com
avatar
MS Brings Cortana Enabled Cards On Bing.com# PDA - 掌中宝
e*e
1
Given a vector of integers, find the longest consecutive sub-sequence of
increasing numbers. If two sub-sequences have the same length, use the one
that occurs first. An increasing sub-sequence must have a length of 2 or
greater to qualify.
Example input:
[1 0 1 2 3 0 4 5]
Result:
[0 1 2 3]
avatar
s*m
2
Microsoft is bringing this personalized experience to the web starting today
. Microsoft is unveiling a set of personalized cards on the Bing homepage
that will help you keep track of things that matter to you. Set up your
interests in Bing settings and you will start seeing personalized news,
weather, flights, and stocks with more to come – all as part of the search
experience.
avatar
e*e
3
我的解法,总觉得用Java写还有更好的。
public class LongestConsecutiveSubsequence {

private int longestLCSStartPos = 0;
private int longestLCSCount = 0;
public Vector lcs(Vector input) {
if( input == null || input.size() < 2 )
throw new RuntimeException( "Invalid input." );

lcs( input, 0 );
if ( longestLCSCount < 2 )
throw new RuntimeException( "lcs length is less than 2." );

Vector r = new Vector();
for( int i = 0 ; i < longestLCSCount; i++ )
r.add( input.get( i + longestLCSStartPos ) );
return r;
}

private void lcs(Vector input, int startPos ) {
if( startPos == input.size() - 1 )
return;

int lcsStartPos = findNextBottomPos( input, startPos );
int lcsEndPos = findNextTopPos( input, lcsStartPos );
int lcsCount = lcsEndPos - lcsStartPos + 1;

if( lcsCount > longestLCSCount) {
longestLCSStartPos = lcsStartPos;
longestLCSCount = lcsCount;
}

lcs( input, lcsEndPos );
}

private int findNextBottomPos( Vector input, int startPos ) {
while( startPos + 1 < input.size() && input.get( startPos + 1 ) <=
input.get( startPos ) )
startPos++;
return startPos;
}

private int findNextTopPos( Vector input, int startPos ) {
while( startPos + 1 < input.size() && input.get( startPos + 1 ) >
input.get( startPos ) )
startPos++;
return startPos;
}
}
avatar
r*h
4
连续递增子串的话,从左往右扫一轮不就可以了吗
int i=0, j, maxLength=0;
while(i < A.length-1){
while(A[i]> A[i+1] && ii++;
j = i+1;
while(jA[j-1])
j++;
if(maxLength < j-i)
maxLength = j-i;
i = j;
}
if(maxLength <= 1)
return 0;
return maxLength;

【在 e****e 的大作中提到】
: Given a vector of integers, find the longest consecutive sub-sequence of
: increasing numbers. If two sub-sequences have the same length, use the one
: that occurs first. An increasing sub-sequence must have a length of 2 or
: greater to qualify.
: Example input:
: [1 0 1 2 3 0 4 5]
: Result:
: [0 1 2 3]

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。