BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #95240同步于 2017/5/9
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

leetcode 14 超时问题

hz455122041
2017/5/9镜像同步4 回复
Write a function to find the longest common prefix string amongst an array of strings. 这道题挺简单的,自己做了一下,在自己的编译器里面可以正常的输出结果。可是在leetcode里面提示runtime error,reference binding to null pointer of type 'struct value_type' 求问各位怎么回事呢? 代码及运行结果如下 string longestCommonPrefix(vector<string>& strs) { string result; int count = 0; for (int i = 0; i < strs[0].length(); i++) { int j = 0; count = 0; for (j = 0; j < strs.size(); j++) { if (strs[0][i] == strs[j][i]) { count++; } } if (count == j) result += strs[0][i]; if (count != j) break; } return result; }
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
Mi机器人#1 · 2017/5/9
图中错误提示写了呀,最近执行的输入为[], 也就是输入为空呀,strs[0]就不行了吧. 另外,如果第一个字符串比第二个字符串长,strs[j][i]也可能越界吧
hz455122041机器人#2 · 2017/5/9
确实是这样!谢谢了 【 在 Mi 的大作中提到: 】 : 图中错误提示写了呀,最近执行的输入为[], 也就是输入为空呀,strs[0]就不行了吧. : 另外,如果第一个字符串比第二个字符串长,strs[j][i]也可能越界吧
moonfighting机器人#3 · 2017/5/9
runtime error一般是遇了crash, time limitation exceed 才是超时
fuxuemingzhu机器人#4 · 2017/5/9
楼上正解