Skip to content

Commit 94de7fb

Browse files
authored
Update 0611-valid-triangle-number.md
1 parent 6322c74 commit 94de7fb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

dsa-solutions/lc-solutions/0600-0699/0611-valid-triangle-number.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Output: 4
4040

4141
## Solution for Valid Triangle Number
4242

43-
### Approach #1 Brute Force [Time Limit Exceeded]
43+
### Approach 1 Brute Force [Time Limit Exceeded]
4444

4545
The condition for the triplets (a,b,c) representing the lengths of the sides of a triangle, to form a valid triangle, is that the sum of any two sides should always be greater than the third side alone. i.e. a+b>c, b+c>a, a+c>b.
4646

@@ -131,7 +131,7 @@ class Solution:
131131

132132
> **Reason**: Constant space is used.
133133

134-
### Approach #2 Using Binary Search
134+
### Approach 2 Using Binary Search
135135
#### Algorithm
136136

137137
If we sort the given `nums` array once, we can solve the problem more efficiently. This is because if we consider a triplet `(a, b, c)` such that $$a \leq b \leq c$$, we need not check all three inequalities for the validity of the triangle formed by them. Only the condition $$a + b > c$$ is necessary. This happens because $$c \geq b$$ and $$c \geq a$$. Thus, adding any number to c will always produce a sum greater than either a or b considered alone. Therefore, the inequalities $$c + a > b$$ and $$c + b > a$$ are satisfied implicitly by the property $$a < b < c$$.

0 commit comments

Comments
 (0)