forked from mmistakes/minimal-mistakes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Rename the post -add describtion
- Loading branch information
Showing
2 changed files
with
28 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
layout: single | ||
title: "Programmers_폰켓몬(Hash, Dictionary)" | ||
--- | ||
|
||
## 딕셔너리(Key-Value)를 사용한 파이썬 풀이 | ||
|
||
```python | ||
def solution(nums): | ||
answer = 0 | ||
l = len(nums) | ||
pocketmons = {} #dic {포켓몬 번호 : 개수} | ||
for i in nums: | ||
if i in pocketmons: | ||
pocketmons[i] += 1 #키가 있다면 개수 + 1 | ||
else: | ||
pocketmons[i] = 1 #키가 없다면 1로 초기화 | ||
|
||
# 포켓몬 키 값 개수(중복 없음) | ||
answer = len(pocketmons.keys()) | ||
|
||
#구한 값이 l/2와 같거나 크다면 l/2가 답 | ||
if answer >= l/2: | ||
answer = l/2 | ||
|
||
return answer | ||
|
||
``` |
This file was deleted.
Oops, something went wrong.