爱奇艺算法第一题超时 求分享思路

爱奇艺第一题,解法有点偏暴力,Python超时了,没有AC 求思路分享 谢谢!#爱奇艺##笔试题目#
全部评论
#include <iostream> #include <string> #include <vector> //#include <math.h> #include<algorithm> using namespace std; int main() { string  s,t; getline(cin, s, '\n'); getline(cin, t, '\n'); int lens = s.size(); vector<int> res; int lent = t.size(); int l = 0,c=0; while (l<=lens-lent) { if (s.substr(l, lent) == t) { for (int i = 0; i < lent-1; i++) res.push_back(c); c++; res.push_back(c); l += lent; } else{ res.push_back(c); l++; } } for (int j = lens - lent+1; j < lens; j++) res.push_back(c); for (int k = 0; k < lens; k++) cout << res[k]; //system("pause"); return 0; }
点赞 回复 分享
发布于 2019-09-20 14:31
取要求次数最多的一个人与次数最少的两个人的和,的较大值
点赞 回复 分享
发布于 2019-09-19 00:36
第一题,c++中关于string 有一个find 函数,可以在较长字符串中查找较短字符串的位置
点赞 回复 分享
发布于 2019-09-18 21:24
问下第二题的案例
点赞 回复 分享
发布于 2019-09-18 21:08
你是用的str.count?
点赞 回复 分享
发布于 2019-09-18 21:06

相关推荐

不愿透露姓名的神秘牛友
07-07 13:35
虽然不怎么光彩,经过这件事,可能我真的要去认同“面试八股文早该淘汰!不会用AI作弊的程序员=新时代文盲!”这句话了
HellowordX:Ai的出现是解放劳动力的,不是用来破坏公平竞争环境的,这样下去,轻则取消所有线上面试,严重了会影响整个行业对所有人产生影响,企业会拉高入职考核各种离谱考核会层出不穷
你找工作的时候用AI吗?
点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
05-26 09:07
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务