Given an array of integers, count how many triplets can form the sides of a valid triangle. Sorting lets you fix the largest side and count valid pairs with two pointers.
nums = array of non-negative integers
count of valid triangles
Example 1:
Input:
nums = [2,2,3,4]
Output:
3
Explanation:
The valid triangles are (2,3,4), (2,3,4), and (2,2,3).
Example 2:
Input:
nums = [4,2,3,4]
Output:
4
Explanation:
There are four valid triplets after sorting.