You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
greedy. suppose we can form any integer in [0,m) using the first j numbers, let x be the (j+1)-th number. if x<=m, we can expand [0,m) to [0,m)+[x,x+m)=[0,x+m), otherwise greedily add a new number m, and expand to [0,2m). using O(log n) integers are sufficient, so time O(n'+log n).
Copy file name to clipboardExpand all lines: 0601-0700/611. Valid Triangle Number.txt
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@ let the range of the numbers be O(U).
2
2
1. O(n^2) by double pointers, enumerate one number.
3
3
2. we can reduce this problem to the tripartite version of 259. 3Sum Smaller, wlog assume a[i]<=a[j]<=a[k], can form a triangle iff a[i]+a[j]>a[k], i.e. a[i]+a[j]-a[k]>0. use a counting argument. O(n+U log U).
4
4
5
-
note. is this problem 3sum-hard?
6
-
if we allow negative edge weights (which doesn't make sense in geometry), we can reduce the tripartite version of 3sum to the tripartite version of this problem.
5
+
note. this problem is 3sum-hard.
6
+
1. If we allow negative edge weights (which doesn't make sense in geometry), we can reduce the tripartite version of 3sum to the tripartite version of this problem.
7
+
2. We can reduce 3sum to this problem, by first count the number of solutions once, then add each number by eps and count again. If the count differs then there's a 3sum solution.
knapsack/subset sum. O~(t^1.5). See my article https://leetcode.cn/problems/length-of-the-longest-subsequence-that-sums-to-target/solutions/3041311/geng-kuai-de-ot15de-suan-fa-by-hqztrue-47yj/
2
+
Remark. better algorithm?
3
+
Collapse file: 2901-3000/2942. Find Words Containing Character.txt
0 commit comments