Skip to content

Commit aacb0e7

Browse files
another idea for 1636
1 parent d06ad71 commit aacb0e7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

problems/1636/jeremymanning.md

+18
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,21 @@ class Solution:
2828
![Screenshot 2024-07-22 at 8 13 33 PM](https://github.com/user-attachments/assets/2a22346c-4997-486e-a79d-8e473d4b78b3)
2929

3030
Solved!
31+
32+
- Actually: Maybe we can save some memory by not re-storing the counts:
33+
```python
34+
class Solution:
35+
def frequencySort(self, nums: List[int]) -> List[int]:
36+
counts = {}
37+
for n in nums:
38+
if n in counts:
39+
counts[n] += 1
40+
else:
41+
counts[n] = 1
42+
43+
return [n for n in sorted(nums, key=lambda x: [counts[x], -x])]
44+
```
45+
46+
![Screenshot 2024-07-22 at 8 16 25 PM](https://github.com/user-attachments/assets/db39e587-23c4-4974-bcd6-7ca5ab2c48c0)
47+
48+
Nope, not helpful 🙃!

0 commit comments

Comments
 (0)