1331. Rank Transform of an Array Easy

@problem@discussion
#Array#Hash Table#Sorting



1/**
2 * [1331] Rank Transform of an Array
3 *
4 * Given an array of integers arr, replace each element with its rank.
5 * The rank represents how large the element is. The rank has the following rules:
6 * 
7 * 	Rank is an integer starting from 1.
8 * 	The larger the element, the larger the rank. If two elements are equal, their rank must be the same.
9 * 	Rank should be as small as possible.
10 * 
11 *  
12 * Example 1:
13 * 
14 * Input: arr = [40,10,20,30]
15 * Output: [4,1,2,3]
16 * Explanation: 40 is the largest element. 10 is the smallest. 20 is the second smallest. 30 is the third smallest.
17 * Example 2:
18 * 
19 * Input: arr = [100,100,100]
20 * Output: [1,1,1]
21 * Explanation: Same elements share the same rank.
22 * 
23 * Example 3:
24 * 
25 * Input: arr = [37,12,28,9,100,56,80,5,12]
26 * Output: [5,3,4,2,8,6,7,1,3]
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	0 <= arr.length <= 10^5
32 * 	-10^9 <= arr[i] <= 10^9
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/rank-transform-of-an-array/
38// discuss: https://leetcode.com/problems/rank-transform-of-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn array_rank_transform(arr: 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_1331() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.