Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래머스
- Git
- 코로나19
- Docker
- Kaggle
- AI 경진대회
- 백준
- 우분투
- ubuntu
- 자연어처리
- gs25
- 더현대서울 맛집
- programmers
- SW Expert Academy
- Baekjoon
- ChatGPT
- 파이썬
- 프로그래머스 파이썬
- 편스토랑 우승상품
- dacon
- hackerrank
- leetcode
- 데이콘
- Real or Not? NLP with Disaster Tweets
- 편스토랑
- 캐치카페
- 맥북
- github
- PYTHON
- 금융문자분석경진대회
Archives
- Today
- Total
솜씨좋은장씨
[Programmers] 스택/큐 : 기능개발 (Python) 본문
728x90
반응형
1일 1문제 19일차!
오늘의 문제는 프로그래머스의 기능개발 입니다.
첫번째 시도
이 문제를 풀기위해서 dictionary를 사용하기로 생각해보았습니다.
def solution(progresses, speeds):
answer = []
min_key = 0
work_times_dic = {}
for i in range(len(progresses)):
work_time = (100 - progresses[i]) // speeds[i]
if (100-progresses[i]) % speeds[i] != 0:
work_time = work_time + 1
my_keys = work_times_dic.keys()
if i > 0:
min_key = min(my_keys)
if min_key < work_time and (work_time not in my_keys):
work_times_dic[work_time] = 1
elif min_key > work_time:
work_times_dic[min_key] = work_times_dic[min_key] + 1
work_times_dic = sorted(work_times_dic.items())
for i in range(len(work_times_dic)):
answer.append(work_times_dic[i][1])
return answer
두번째 시도
dictionary에 값을 추가하는 조건을 추가해보았습니다.
def solution(progresses, speeds):
answer = []
min_key = 0
work_times_dic = {}
for i in range(len(progresses)):
work_time = (100 - progresses[i]) // speeds[i]
if (100-progresses[i]) % speeds[i] != 0:
work_time = work_time + 1
my_keys = work_times_dic.keys()
if i > 0:
min_key = min(my_keys)
if min_key < work_time and (work_time not in my_keys):
work_times_dic[work_time] = 1
elif min_key > work_time:
work_times_dic[min_key] = work_times_dic[min_key] + 1
else:
work_times_dic[work_time] = work_times_dic[work_time] + 1
work_times_dic = sorted(work_times_dic.items())
for i in range(len(work_times_dic)):
answer.append(work_times_dic[i][1])
return answer
세번째 시도
key로 사용되고 있는 변수들을 stack에 저장하여 확인하도록 하였습니다.
def solution(progresses, speeds):
answer = []
min_key = 0
finish_time = []
finish_time_stack = []
for i in range(len(progresses)):
work_time = (100 - progresses[i]) // speeds[i]
if (100-progresses[i]) % speeds[i] != 0:
work_time = work_time + 1
finish_time.append(work_time)
finish_time_dic = {finish_time[0]:1}
finish_time_stack.append(finish_time[0])
for i in range(1, len(finish_time)):
if finish_time[i-1] > finish_time[i]:
finish_time_dic[finish_time[i-1]] = finish_time_dic[finish_time[i-1]] + 1
elif finish_time[i] not in finish_time_dic.keys():
finish_time_dic[finish_time[i]] = 1
finish_time_stack.append(finish_time[i])
else:
finish_time_dic[finish_time[i]] = finish_time_dic[finish_time[i]] + 1
for key in finish_time_dic.keys():
answer.append(finish_time_dic[key])
print(finish_time_dic)
return answer
네번째 시도
조건을 수정하여 도전해보았습니다.
def solution(progresses, speeds):
answer = []
min_key = 0
finish_time = []
finish_time_stack = []
for i in range(len(progresses)):
work_time = (100 - progresses[i]) // speeds[i]
if (100-progresses[i]) % speeds[i] != 0:
work_time = work_time + 1
finish_time.append(work_time)
finish_time_stack.append(finish_time[0])
finish_time_dic = {finish_time[0]:1}
for i in range(1, len(finish_time)):
if finish_time[i-1] < finish_time[i] and (finish_time[i] > finish_time_stack[-1]):
finish_time_dic[finish_time[i]] = 1
finish_time_stack.append(finish_time[i])
else:
finish_time_dic[finish_time_stack[-1]] = finish_time_dic[finish_time_stack[-1]] + 1
for key in finish_time_dic.keys():
answer.append(finish_time_dic[key])
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[Programmers] 해시 : 베스트앨범 (Python) (2) | 2020.02.27 |
---|---|
[Programmers] 스택/큐 : 주식가격 (Python) (0) | 2020.02.26 |
[Programmers] 해시 : 전화번호 목록 (Python) (9) | 2020.02.24 |
[Programmers] 완전탐색 : 모의고사 (Python) (0) | 2020.02.22 |
[leetCode] 2. Add Two Numbers (Python) (0) | 2020.02.21 |
Comments