Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- node.js
- HTML
- ํ์ด์ฌ
- ์ฝ๋ฉํ ์คํธ
- heapq
- ์ฝ๋ฉ
- ํ๋ก ํธ์๋
- javascript
- ๋ชจ๊ฐ์ฝ
- mongodb
- Til
- ๋๋ฆผ์ฝ๋ฉ
- ๊ตญ๋น์ง์
- JS
- error
- fe
- ์๊ณ ๋ฆฌ์ฆ
- ๊ทธ๋ฆฌ๋
- Python
- ํ๋ก์ ํธ
- ํฌ๋กค๋ง
- react
- ํ ์ดํ๋ก์ ํธ
- ๋ฐฑ์ค
- ๊ฐ๋ฐ
- ๋ ธ๋ง๋์ฝ๋
- ํ๋ก๊ทธ๋๋จธ์ค
- CSS
- KDT
- ์ฝ๋ฉ์ ํ
Archives
- Today
- Total
๐ฑ → ๐ณ
[ํ๋ก๊ทธ๋๋จธ์ค] ์ ํ๋ฒํธ ๋ชฉ๋ก - python ๋ณธ๋ฌธ
728x90
๋ฌธ์ ์ ๋ณด
https://school.programmers.co.kr/learn/courses/30/lessons/42577
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
์ฝ๋
์๊ฐ ์ด๊ณผ ๋ฐ ๋ช๊ฐ์ ํ ์คํธ์์ ์คํจ
def solution(phone_book):
answer = True
for i in range(len(phone_book)):
for j in range(i+1, len(phone_book)):
if phone_book[i] in phone_book[j]:
answer = False
return answer
→ ๋ฐ๋ก ์ฐพ์๋ณด๊ธฐ
((์์ ))
์๊ณ ์ ๋ ฌํ๋ฉด ๋จ
["1234", "12"] ์ผ๋๋ฅผ ์ฒดํฌ ๋ชปํจ
์ ๋ ฌํ๋ฉด ["12", "1234"] ์ฌ์ ์ฒดํฌ ๊ฐ๋ฅ
์ ๋ต์ฝ๋
def solution(phone_book):
answer = True
phone_book.sort()
for i in range(len(phone_book)-1):
if phone_book[i] == phone_book[i+1][:len(phone_book[i])]:
answer = False
break
return answer
def solution(phoneBook):
phoneBook = sorted(phoneBook)
for p1, p2 in zip(phoneBook, phoneBook[1:]):
if p2.startswith(p1):
return False
return True
728x90
'Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ๋์คํฌ ์ปจํธ๋กค๋ฌ - python (0) | 2023.08.31 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ํ๋ก์ธ์ค - python (0) | 2023.08.30 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ ์ฐพ๊ธฐ - python (0) | 2023.08.25 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๊ทค ๊ณ ๋ฅด๊ธฐ - Python (0) | 2023.08.15 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฉ๋ฆฌ๋ฐ๊ธฐ - Python (0) | 2023.08.14 |