Back to course home
0% completed
Solution: Valid Triangle Number
Problem Statement
Given an array of integers nums
, return the number of triplets
we can make using array elements that can create triangle if we take them as side lengths
of a triangle.
A set of three numbers can constitute a triangle if and only if the sum of any two sides
is greater than
the third side
. This condition must hold true for all three combinations of summed sides.
Examples
- Example 1:
- Input:
nums = [4, 2, 3, 1]
- Expected Output:
1
- Justification: The valid combinations that can form a triangle are (2, 3, 4)
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!