Valid Triangle Number
Each item of nums is a stick length. Count the groups of three sticks (taken from three different positions) that can be the sides of a triangle, meaning the two shorter sides add up to more than the longest side.
Example 1
nums [2,2,3,4]
returns 3
Valid: (2,3,4) twice using either 2, and (2,2,3): 3 groups.
Example 2
nums [1,2,3]
returns 0
1 + 2 is not more than 3.
Constraints
1 <= len(nums) <= 200 <= nums[i] <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.