File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ def solution (dirs ):
2+ answer = set ()
3+
4+ move = {
5+ 'U' : (0 , 1 ),
6+ 'D' : (0 , - 1 ),
7+ 'R' : (1 , 0 ),
8+ 'L' : (- 1 , 0 )
9+ }
10+
11+ x , y = 0 , 0
12+ for dir in dirs :
13+ nx , ny = x + move [dir ][0 ], y + move [dir ][1 ]
14+ if - 5 <= nx <= 5 and - 5 <= ny <= 5 :
15+ answer .add ((x , y , nx , ny ))
16+ answer .add ((nx , ny , x , y ))
17+ x , y = nx , ny
18+
19+ return len (answer ) // 2
Original file line number Diff line number Diff line change 1+ import heapq
2+
3+ def time_to_minute (time ):
4+ h , m = map (int , time .split (':' ))
5+ return h * 60 + m
6+
7+ def solution (book_time ):
8+
9+ book = sorted ([[time_to_minute (start ), time_to_minute (end ) + 10 ] for start , end in book_time ])
10+
11+ room = []
12+ for start , end in book :
13+ if room :
14+ early_end = room [0 ] # 가장 빠른 퇴실 시간
15+ if start >= early_end : # 입실 시간이 가장 빠른 퇴실 시간 이후라면 갱신
16+ heapq .heappop (room )
17+ heapq .heappush (room , end )
18+
19+ return len (room )
Original file line number Diff line number Diff line change 1+ def solution (stones , k ):
2+ answer = 0
3+
4+ left , right = 1 , max (stones ) # 나올 수 있는 stones 원소의 최대값
5+ while left <= right :
6+ cnt = 0
7+ mid = (left + right ) // 2
8+ for stone in stones :
9+ if stone <= mid : # mid가 더 크거나 같은 경우 => 0인 경우
10+ cnt += 1
11+ else : cnt = 0 # 0 아닌 경우 다시 0 개수 카운팅
12+ if cnt >= k : break
13+ if cnt < k : # mid가 큰 경우가 적었다는 뜻이니 더 크게 만들기
14+ left = mid + 1
15+ else :
16+ answer = mid
17+ right = mid - 1
18+
19+ return answer
You can’t perform that action at this time.
0 commit comments