728x90
반응형
첫번째 코드
순서대로 정렬한 후에 숫자를 비교하면 되지 않을까?
라는 간단한 아이디어에서 시작하였다!
class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
answer = 0
for i, j in zip(seats, students):
answer += abs(i - j)
return answer
통과
링크
https://github.com/ornni/leetcode/tree/main/2037-minimum-number-of-moves-to-seat-everyone
반응형
'코딩 테스트 > leetcode' 카테고리의 다른 글
Count Items Matching a Rule (0) | 2024.06.19 |
---|---|
Find The Original Array of Prefix Xor (0) | 2024.06.18 |
Range Sum of BST (0) | 2024.06.14 |
Search Insert Position (0) | 2024.06.13 |
Counting Bits (0) | 2024.06.11 |