-
Notifications
You must be signed in to change notification settings - Fork 1
[2023-09-18] sumin #237 #249
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
풀이시간: 10분 | ||
|
||
<input> | ||
word: 단어 하나 | ||
- 길이는 1 이상 5 이하 | ||
- 알파벳 대문자 'A', 'E', 'I', 'O', 'U'로만 이루어져 있음 | ||
|
||
<solution> | ||
만들 수 있는 모든 단어를 만들어도 5**5 = 3125밖에 되지 않기 때문에, | ||
모든 단어를 브루트포스로 만들어 해당 단어가 몇 번째 단어인지 확인한다. | ||
|
||
<시간복잡도> | ||
O(5 ** 5) = O(3125) -> O(1): 상수시간 | ||
사전을 만드는데 가장 오랜 시간이 걸린다. | ||
""" | ||
|
||
mo = "AEIOU" | ||
dic = [] | ||
def go(index: int, alpha: str) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go 함수 내부에서 len(alpha)를 계산한다면 index 매개변수는 안써도 되어 조금 더 좋을 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 재귀 짤때마다 index넘겨주는게 습관이 돼서 다음번 부터는 len을 써보겠습니다..!! 감사합니다 지수님:) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와 재귀를 생각하신건 정말 대단하신 것 같아요 재귀의 특성을 정확히 이해하고 계신 것에 감탄이 나옵니다. |
||
# 종료조건(최대 단어의 길이는 5) | ||
if index == 6: | ||
return | ||
if index != 0: # 단어를 사전에 추가 | ||
dic.append(alpha) | ||
for i in range(5): | ||
go(index+1, alpha+mo[i]) | ||
|
||
|
||
def solution(word: str) -> int: | ||
go(0, '') | ||
for i, w in enumerate(dic, start=1): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. start=1 이라는 옵션은 처음 보네요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 222222 이러면 인덱스가 1부터 시작하군요.. |
||
if w == word: # 해당 단어가 사전에 존재하면 index(순서) 반환 | ||
return i | ||
|
||
""" | ||
정확성 테스트 | ||
테스트 1 〉 통과 (4.06ms, 10.4MB) | ||
테스트 2 〉 통과 (4.90ms, 10.4MB) | ||
테스트 3 〉 통과 (8.30ms, 10.5MB) | ||
테스트 4 〉 통과 (4.25ms, 10.4MB) | ||
테스트 5 〉 통과 (4.60ms, 10.5MB) | ||
테스트 6 〉 통과 (4.16ms, 10.3MB) | ||
테스트 7 〉 통과 (4.49ms, 10.6MB) | ||
테스트 8 〉 통과 (9.41ms, 10.4MB) | ||
테스트 9 〉 통과 (4.21ms, 10.5MB) | ||
테스트 10 〉 통과 (4.46ms, 10.4MB) | ||
테스트 11 〉 통과 (7.87ms, 10.4MB) | ||
테스트 12 〉 통과 (9.05ms, 10.4MB) | ||
테스트 13 〉 통과 (8.67ms, 10.4MB) | ||
테스트 14 〉 통과 (4.16ms, 10.3MB) | ||
테스트 15 〉 통과 (4.48ms, 10.4MB) | ||
테스트 16 〉 통과 (7.16ms, 10.5MB) | ||
테스트 17 〉 통과 (7.72ms, 10.4MB) | ||
테스트 18 〉 통과 (4.47ms, 10.5MB) | ||
테스트 19 〉 통과 (4.63ms, 10.4MB) | ||
테스트 20 〉 통과 (7.48ms, 10.4MB) | ||
테스트 21 〉 통과 (8.49ms, 10.4MB) | ||
테스트 22 〉 통과 (6.64ms, 10.4MB) | ||
테스트 23 〉 통과 (4.60ms, 10.5MB) | ||
테스트 24 〉 통과 (7.77ms, 10.6MB) | ||
테스트 25 〉 통과 (8.50ms, 10.4MB) | ||
테스트 26 〉 통과 (6.68ms, 10.4MB) | ||
테스트 27 〉 통과 (4.46ms, 10.4MB) | ||
테스트 28 〉 통과 (4.53ms, 10.4MB) | ||
테스트 29 〉 통과 (4.27ms, 10.5MB) | ||
테스트 30 〉 통과 (4.82ms, 10.4MB) | ||
테스트 31 〉 통과 (4.38ms, 10.4MB) | ||
테스트 32 〉 통과 (4.70ms, 10.3MB) | ||
테스트 33 〉 통과 (8.94ms, 10.3MB) | ||
테스트 34 〉 통과 (8.46ms, 10.3MB) | ||
테스트 35 〉 통과 (6.07ms, 10.4MB) | ||
테스트 36 〉 통과 (4.56ms, 10.5MB) | ||
테스트 37 〉 통과 (8.92ms, 10.4MB) | ||
테스트 38 〉 통과 (7.27ms, 10.5MB) | ||
테스트 39 〉 통과 (6.75ms, 10.4MB) | ||
테스트 40 〉 통과 (8.44ms, 10.4MB) | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굳이 따지자면(?) 모든 단어의 길이가 5가 아니기 때문에 경우의수가 더 늘어나긴 합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
옹 5!이 맞는 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제 코드상으로 굳이 따지면 5^6이긴한데 어차피 return되니까 5^5로 생각했어요!

5!은 아니에요!!