-
Notifications
You must be signed in to change notification settings - Fork 0
/
완주하지못한선수.py
62 lines (40 loc) · 1.32 KB
/
완주하지못한선수.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 8 13:36:00 2021
@author: user
"""
#프로그래머스
#level1 연습
#완주하지 못한 선수
#루프 이용한 풀이
def solution(participant, completion):
answer = ''
participant.sort()
completion.sort()
completion.append(1)
for i in range(len(participant)):
if participant[i] != completion[i] :
answer = participant[i]
return answer
#실행
participant = ["mislav", "stanko", "mislav", "ana"]
completion = ["stanko", "ana", "mislav"]
print(solution(participant, completion))
### 이 문제 풀이는 동명이인을 처리하지 못함 ㅠ ####
#%%
#hash 이용한 풀이
def solution(participant, competion) :
answer = ''
temp = 0
dic = {}
for part in participant :
dic[hash(part)] = part #dictionary에 key(hash값)-value(이름) 쌍을 추가, key 값은 중복 허용 안됨.
temp += int(hash(part)) #hash값 중첩시킴
for com in competion :
temp -= hash(com) #value에 대한 hash값을 제거해서 도착 안한 사람의 hash의 key값만 남음
answer = dic[temp]
return answer
#실행
participant = ["mislav", "stanko", "mislav", "ana"]
completion = ["stanko", "ana", "mislav"]
print(solution(participant, completion))