avatar
spg 可以refer ld 吗?# Money - 海外理财
a*e
1
class Solution {
public:
Write a function to find the longest common prefix string amongst an array
of strings.
The Time complexity is O(logM * N), while M is the size of strs, N is the
shortest length of the str in the strs
而我觉得这个时间复杂度应该是O(MN). 因为isEqual()的复杂度应该是O(M), as T(M
) = 2T(M/2) + O(1). 谢谢。
============================
bool isEqual(vector &strs, int index, int start, int end) {
if(end < start) return true;
if(end == start) {
if(strs[start].size() > index) return true;
else return false;
}
int mid = (start + end) / 2;
bool lEqual = isEqual(strs, index, start, mid);
bool rEqual = isEqual(strs, index, mid + 1, end);
if(!lEqual || !rEqual) return false;
if(index > strs[start].size()) return false;
if(index > strs[end].size()) return false;
if(strs[start][index] != strs[end][index]) return false;
return true;
}
string longestCommonPrefix(vector &strs) {
// Note: The Solution object is instantiated only once and is reused by
each test case.
string res;
size_t vSize = strs.size();
if(0 == vSize) return res;
if(1 == vSize) return strs[0];
int len = 0;
while(isEqual(strs, len, 0, vSize - 1)) {
len ++;
}
res = strs[0].substr(0, len);
return res;
}
avatar
m*g
2
周日refer 的,也申了,批了. 可referal points 还没收到.
avatar
k*k
3
Wait 7 days
avatar
D*i
4
refer LD,LD也是35000么?
avatar
t*2
5
应该可以吧 哈哈
avatar
m*g
6
这么久? 去年REFER 我记得就4,5天呀.

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