由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ 程序求助
相关主题
请教一道题Longest Palindromic Substring O(N) 算法
Longest Palindromic Substring 用 vector 超时LC Longest substr w/o rep char
问一个题,求相同元素最多的两个数组问下careercup上的这一题
Palindrome Partitioning II 的DP做法?报个微软的Offer
Zenefits面经(已挂)facebook电面估计挂了
Amazon Summer Intern Offer, 发面经专家们,find the longest common substring of two strings
(已解决,code错了) online judge 有的时候会有点小bug吗?问问题
longest common prefix 和 longest common substring请问驿道面试题
相关话题的讨论汇总
话题: dp话题: int话题: c++话题: vector话题: cout
进入JobHunting版参与讨论
1 (共1页)
C******a
发帖数: 32
1
考虑有相同元素情形.需要给出compact, clean code, C or C++.
Write a C++ program that print the first longest
ascending or descending contiguous substring for a vector of integers. Given
a vector
4, 2, 1, 2, 3, 4, 3, 5, 1, 2, 4, 6, 5
the program would print:
1, 2, 3, 4
算法不难,但写不出简短的clean code. 欢迎讨论.
b********h
发帖数: 119
2
void las(vector v)
{
vector dp(v.size(), 1);
pair max(0, 1);
for(int i = 1; i < v.size(); ++i)
{
if(v[i] > v[i-1]) {
dp[i] = dp[i-1]+1;
if(dp[i] > max.second)
{
max.second = dp[i];
max.first = i;
}
}
else
dp[i] = 1;
}
for(int i = max.first-max.second+1; i <= max.first; ++i)
cout< cout< }
C******a
发帖数: 32
3
Seems this only finds out ascending substrings, right?

【在 b********h 的大作中提到】
: void las(vector v)
: {
: vector dp(v.size(), 1);
: pair max(0, 1);
: for(int i = 1; i < v.size(); ++i)
: {
: if(v[i] > v[i-1]) {
: dp[i] = dp[i-1]+1;
: if(dp[i] > max.second)
: {

1 (共1页)
进入JobHunting版参与讨论
相关主题
请问驿道面试题Zenefits面经(已挂)
Ask a google interview question(3)Amazon Summer Intern Offer, 发面经
问个缺少逗号的数组赋值问题(已解决,code错了) online judge 有的时候会有点小bug吗?
求解, 我怎么觉得longest common substring问题,brute force 比DP还好啊?longest common prefix 和 longest common substring
请教一道题Longest Palindromic Substring O(N) 算法
Longest Palindromic Substring 用 vector 超时LC Longest substr w/o rep char
问一个题,求相同元素最多的两个数组问下careercup上的这一题
Palindrome Partitioning II 的DP做法?报个微软的Offer
相关话题的讨论汇总
话题: dp话题: int话题: c++话题: vector话题: cout