| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- 뭐든
- 영어공부
- 10분
- 파비최
- Writing
- 스탭퍼
- 월간
- 읽기
- 운동
- 쓰릴오브파이트
- 괜찮음
- English
- realclass
- 미드시청
- 만화도
- 개발자
- 프로젝트
- 리얼 클래스
- FIT XR
- 30분
- Daily Challenge
- 화상영어
- leetcode
- 영어원서읽기
- Problem Solving
- 링피트
- 사이드
- 잡생각
- 3줄정리
- 매일
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.10.31 Today's Challenge 본문
https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/
Sort Integers by The Number of 1 Bits - LeetCode
Can you solve this real interview question? Sort Integers by The Number of 1 Bits - You are given an integer array arr. Sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more integ
leetcode.com
오랫만에 직접 품.
좀 더 간단한 방법이 있을지도..
class Solution:
def sortByBits(self, arr: List[int]) -> List[int]:
d = {}
res = []
for v in arr:
k = bin(v).count('1')
if not d.get(k):
d[k] = [v]
continue
d[k].append(v)
d = sorted(d.items())
for dd in d:
res.extend(sorted(dd[1]))
return res반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.11.02 Today's Challenge (0) | 2023.11.02 |
|---|---|
| 2023.11.01 Today's Challenge (0) | 2023.11.01 |
| 2023.10.30 Today's Challenge (0) | 2023.10.30 |
| 2023.10.29 Today's Challenge (0) | 2023.10.29 |
| 2023.10.28 Today's Challenge (0) | 2023.10.28 |
Comments