avatar
N*8
2
Given a array of positive integers, find all possible triangle triplets that
can be formed from this array.
eg: 9 8 10 7
ans: 9 8 10, 9 8 7, 9 10 7, 7 8 10
Note : array not sorted, there is no limit on the array length
geeks4geeks有类似的,但是只是求三角形个数的,能用n^2事件复杂度解出来。但是如
果求所有的三边的输出,感觉还是要n^3。请教大家的优化方法。
avatar
h*e
3
我日,被骗了,今天才9号。
avatar
w*a
4
感觉就是3 sum变种题
avatar
m*t
5
白忙活了,是明天。
avatar
r*7
6
要是需要输出所有的话,必然要n^3吧,extreme的case是所有的组合都是valid的,就
必然有n^3个结果啊

that

【在 N*****8 的大作中提到】
: Given a array of positive integers, find all possible triangle triplets that
: can be formed from this array.
: eg: 9 8 10 7
: ans: 9 8 10, 9 8 7, 9 10 7, 7 8 10
: Note : array not sorted, there is no limit on the array length
: geeks4geeks有类似的,但是只是求三角形个数的,能用n^2事件复杂度解出来。但是如
: 果求所有的三边的输出,感觉还是要n^3。请教大家的优化方法。

avatar
Z*L
7
hp17?

【在 m******t 的大作中提到】
: 白忙活了,是明天。
avatar
N*8
8
我觉得也是,最近有个朋友被L问到这道题目,他用N^3解出来了,但是老中主面试官貌
似不满意,所以就有点疑惑了。

【在 r****7 的大作中提到】
: 要是需要输出所有的话,必然要n^3吧,extreme的case是所有的组合都是valid的,就
: 必然有n^3个结果啊
:
: that

avatar
L*1
9
chi
avatar
G*n
10
sort + two pointer + combination
avatar
f*n
11
就在那一秒,我们做个一秒钟的朋友

【在 h*e 的大作中提到】
: congs
avatar
m*k
12
5,4,3,1
可否用这个input示范一下?

【在 G*********n 的大作中提到】
: sort + two pointer + combination
avatar
m*r
13
lol

【在 h*e 的大作中提到】
: 我日,被骗了,今天才9号。
avatar
w*a
14
怎么弄都还是O(n^3)吧
avatar
y*u
15
cong

【在 h*e 的大作中提到】
: congs
avatar
c*y
16
没到呢

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