3769. Sort Integers by Binary Reflection Easy

@problem@discussion
#Array#Sorting



1/**
2 * [3769] Sort Integers by Binary Reflection
3 *
4 * You are given an integer array nums.
5 * The binary reflection of a positive integer is defined as the number obtained by reversing the order of its binary digits (ignoring any leading zeros) and interpreting the resulting binary number as a decimal.
6 * Sort the array in ascending order based on the binary reflection of each element. If two different numbers have the same binary reflection, the smaller original number should appear first.
7 * Return the resulting sorted array.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">nums = [4,5,4]</span>
12 * Output: <span class="example-io">[4,4,5]</span>
13 * Explanation:
14 * Binary reflections are:
15 * 
16 * 	4 -> (binary) 100 -> (reversed) 001 -> 1
17 * 	5 -> (binary) 101 -> (reversed) 101 -> 5
18 * 	4 -> (binary) 100 -> (reversed) 001 -> 1
19 * Sorting by the reflected values gives [4, 4, 5].</div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">nums = [3,6,5,8]</span>
23 * Output: <span class="example-io">[8,3,6,5]</span>
24 * Explanation:
25 * Binary reflections are:
26 * 
27 * 	3 -> (binary) 11 -> (reversed) 11 -> 3
28 * 	6 -> (binary) 110 -> (reversed) 011 -> 3
29 * 	5 -> (binary) 101 -> (reversed) 101 -> 5
30 * 	8 -> (binary) 1000 -> (reversed) 0001 -> 1
31 * Sorting by the reflected values gives [8, 3, 6, 5].<br />
32 * Note that 3 and 6 have the same reflection, so we arrange them in increasing order of original value.</div>
33 *  
34 * Constraints:
35 * 
36 * 	1 <= nums.length <= 100
37 * 	1 <= nums[i] <= 10^9
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/sort-integers-by-binary-reflection/
43// discuss: https://leetcode.com/problems/sort-integers-by-binary-reflection/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn sort_by_reflection(nums: Vec<i32>) -> Vec<i32> {
49        vec![]
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_3769() {
61    }
62}
63

Back
© 2026 bowen.ge All Rights Reserved.