-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_1874.py
More file actions
37 lines (29 loc) · 933 Bytes
/
baekjoon_1874.py
File metadata and controls
37 lines (29 loc) · 933 Bytes
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
31
32
33
34
35
36
class Solution:
def stack_sequence(self,nums):
temp = True
stack = []
answer = []
count = 1
for num in nums:
while count <= num: # 입력된 수열보다 작은 경우 같아질 때까지 반복
stack.append(count)
answer.append('+')
count += 1
if stack[-1] == num: # 입력된 수열과 동일한 경우
stack.pop()
answer.append('-')
else: # 특정 수열을 만들 수 없을 경우
temp = False
if not temp:
return 'NO'
else:
li = []
for i in answer:
li.append(i)
return '\n'.join(li)
if __name__ == "__main__":
s = Solution()
nums = [4, 3, 6, 8, 7, 5, 2, 1]
print(s.stack_sequence(nums))
nums = [1 ,2 ,5 ,3 ,4]
print(s.stack_sequence(nums))