Skip to content

Commit 699afbb

Browse files
authored
Add files via upload
1 parent 48de4a9 commit 699afbb

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

LEVEL2/Day1/pocketmon.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
# 첫 풀이
12
def solution(nums):
23

3-
mySet = set(nums)
4-
if len(mySet) > int(len(nums)/2) :
4+
pocketmon = set(nums)
5+
if len(pocketmon) > int(len(nums)/2) :
56
return int(len(nums)/2)
6-
return len(mySet)
7+
return len(pocketmon)
8+
9+
## 2번재 풀이
10+
11+
def solution(nums):
12+
pocketmon = [] # 새로운 종류의 폰켓몬을 선택하면 이 리스트에 넣음.
13+
for i in nums:
14+
try:
15+
if pocketmon.index(i) >= 0: # 겹치면 answer_list에 추가하지 않기
16+
continue
17+
except:
18+
pocketmon.append(i)
19+
20+
if len(pocketmon) >= len(nums) / 2:
21+
return len(nums) / 2
22+
else:
23+
return len(pocketmon)
24+
25+
return min(len(nums) / 2, len(pocketmon)) # len()을 활용해서 더 간략하게 수정

0 commit comments

Comments
 (0)