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+ """
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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments