1365. How Many Numbers Are Smaller Than the Current Number Easy
1/**
2 * [1365] How Many Numbers Are Smaller Than the Current Number
3 *
4 * Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].
5 * Return the answer in an array.
6 *
7 * Example 1:
8 *
9 * Input: nums = [8,1,2,2,3]
10 * Output: [4,0,1,1,3]
11 * Explanation:
12 * For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3).
13 * For nums[1]=1 does not exist any smaller number than it.
14 * For nums[2]=2 there exist one smaller number than it (1).
15 * For nums[3]=2 there exist one smaller number than it (1).
16 * For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).
17 *
18 * Example 2:
19 *
20 * Input: nums = [6,5,4,8]
21 * Output: [2,1,0,3]
22 *
23 * Example 3:
24 *
25 * Input: nums = [7,7,7,7]
26 * Output: [0,0,0,0]
27 *
28 *
29 * Constraints:
30 *
31 * 2 <= nums.length <= 500
32 * 0 <= nums[i] <= 100
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/
38// discuss: https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn smaller_numbers_than_current(nums: Vec<i32>) -> Vec<i32> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_1365() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.