611. Valid Triangle Number Medium

@problem@discussion
#Array#Two Pointers#Binary Search#Greedy#Sorting



1/**
2 * [611] Valid Triangle Number
3 *
4 * Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.
5 *  
6 * Example 1:
7 * 
8 * Input: nums = [2,2,3,4]
9 * Output: 3
10 * Explanation: Valid combinations are: 
11 * 2,3,4 (using the first 2)
12 * 2,3,4 (using the second 2)
13 * 2,2,3
14 * 
15 * Example 2:
16 * 
17 * Input: nums = [4,2,3,4]
18 * Output: 4
19 * 
20 *  
21 * Constraints:
22 * 
23 * 	1 <= nums.length <= 1000
24 * 	0 <= nums[i] <= 1000
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/valid-triangle-number/
30// discuss: https://leetcode.com/problems/valid-triangle-number/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn triangle_number(nums: Vec<i32>) -> i32 {
36        0
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_611() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.