Skip to content

Commit ce52550

Browse files
authored
Merge pull request #602 from gmlrude/main
[박희경] 87차 라이브 코테 제출
2 parents fbc831e + b4d33c6 commit ce52550

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

live8/test87/문제1/박희경.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
투포인터 -> 몇 테스트케이스에서 시간 초과
3+
스택에 저장한 인덱스 : 아직 뒤에 있는 큰 수를 만나지 못한 인덱스
4+
"""
5+
6+
7+
def solution(numbers):
8+
answer = [-1] * len(numbers)
9+
stack = []
10+
11+
for idx, num in enumerate(numbers):
12+
# 뒤에서 큰 수 만났을 때 case2) stack = [0, 1]
13+
while stack and numbers[stack[-1]] < num:
14+
answer[stack.pop()] = num # 뒤에서 큰 수로 변환 case2) stack = [0]
15+
stack.append(idx) # 가까이 뒤에 큰 수가 없다면
16+
17+
return answer

live8/test87/문제2/박희경.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def solution(people, limit):
2+
answer = 0
3+
people.sort()
4+
5+
start, end = 0, len(people) - 1
6+
while start <= end:
7+
if people[start] + people[end] <= limit:
8+
start += 1
9+
end -= 1
10+
answer += 1
11+
12+
return answer

live8/test87/문제3/박희경.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def solution(dirs):
2+
move = {
3+
"U": (0, 1),
4+
"D": (0, -1),
5+
"R": (1, 0),
6+
"L": (-1, 0)
7+
}
8+
9+
x, y = 0, 0
10+
history = set()
11+
12+
for dir in dirs:
13+
nx, ny = x + move[dir][0], y + move[dir][1]
14+
15+
if -5 <= nx <= 5 and -5 <= ny <= 5:
16+
history.add((x, y, nx, ny))
17+
history.add((nx, ny, x, y))
18+
19+
x, y = nx, ny
20+
21+
return len(history) // 2

0 commit comments

Comments
 (0)