Skip to content

Commit a38b5e0

Browse files
committed
Time: 8 ms (100%), Space: 18.1 MB (100%) - LeetHub
1 parent 9ef46d6 commit a38b5e0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# time complexity: O(nlogn)
2+
# space complexity: O(n)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def sortByReflection(self, nums: List[int]) -> List[int]:
8+
def reflect(x: int) -> int:
9+
b = bin(x)[2:]
10+
rb = b[::-1]
11+
return int(rb, 2)
12+
13+
return sorted(nums, key=lambda x: (reflect(x), x))
14+
15+
16+
nums = [4, 5, 4]
17+
print(Solution().sortByReflection(nums))
18+
nums = [3, 6, 5, 8]
19+
print(Solution().sortByReflection(nums))

0 commit comments

Comments
 (0)