Redian新闻
>
http://ustraveldocs.com/这个网站那么烂啊
avatar
http://ustraveldocs.com/这个网站那么烂啊# Reunion - 探亲与陪读
t*n
1
find and print the first longest ascending or descending contiguous
subsequence for a vector of integers.
avatar
J*1
2
想注册个账号居然说我的EMAIL写的不对,一直不让注册,换个也不行,我发现比以前
麻烦多了,以前直接去柜台就行了
avatar
s*t
3
拿一个counter记住当前最长的ascending,再加一个maxlens,遍历一遍就好了吧。
如果非要descending和ascending那就遍历的时候再加个变量记住吧。
1 2 3 4 5 2 3 1 2 3 5 0
对于只ascending,
从左到右,比较。设置一个flag,标示现在是在递增。用counter记住到底增加了多少
。如果递减了就counter清空。
然后加一个max记住最长的。
avatar
j*p
4
你是怎么解决的呢?我也遇到类似问题,无法注册,正束手无策呢
avatar
s*t
5
我来写一下吧。
int increaseCounter = 1;
int max = 1;
int maxIndex = 0;
for(int i = 1; i < a.length; i++){
if(a[i-1]< a[i]) increaseCounter ++;
else increaseCounter = 1;
if(increaseCounter > max){
max = increaseCounter ;
maxIndex = i-increaseCounter + 1;}
}
avatar
j*p
6
刚才看到另一个帖子,改用英语就好了
avatar
r*o
7
这个subsequence是一个一个挨着的,对吗?

【在 s******t 的大作中提到】
: 拿一个counter记住当前最长的ascending,再加一个maxlens,遍历一遍就好了吧。
: 如果非要descending和ascending那就遍历的时候再加个变量记住吧。
: 1 2 3 4 5 2 3 1 2 3 5 0
: 对于只ascending,
: 从左到右,比较。设置一个flag,标示现在是在递增。用counter记住到底增加了多少
: 。如果递减了就counter清空。
: 然后加一个max记住最长的。

avatar
H*3
8
我当时也高了好久
后来好像换能ie好了, firfox好像不行

【在 j**p 的大作中提到】
: 刚才看到另一个帖子,改用英语就好了
avatar
t*n
9
谢谢!

【在 s******t 的大作中提到】
: 我来写一下吧。
: int increaseCounter = 1;
: int max = 1;
: int maxIndex = 0;
: for(int i = 1; i < a.length; i++){
: if(a[i-1]< a[i]) increaseCounter ++;
: else increaseCounter = 1;
: if(increaseCounter > max){
: max = increaseCounter ;
: maxIndex = i-increaseCounter + 1;}

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