Valid triangle number
Three lengths a ≤ b ≤ c make a triangle when a + b > c. Sort, fix the longest side c from the right, and put left and right below it. If nums[left] + nums[right] > nums[c], every number from left to just below right also works with right: count right − left triangles and move right down. Otherwise left is too short and moves up.