[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์ ํ๋ฒํธ ๋ชฉ๋ก / Python
๐ Problem Solving/Programmers
import sys
input = sys.stdin.readline
phone_book = list(map(str, input().split()))
def solution(phone_book):
phone_book.sort()
for a, b in zip(phone_book, phone_book[1:]):
if a == b[:len(a)]:
return False
return True
print(solution(phone_book))
ํด์ค
๋ฆฌ์คํธ๋ฅผ ์ ๋ ฌํ๋ค.
zip์ ์ด์ฉํด ์ฐ์๋ ๋ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ a, b๋ก ์นํํด์ฃผ๊ณ b์ ์ฒซ a๋งํผ์ ๊ธธ์ด๊ฐ a์ ๊ฐ๋ค๋ฉด ์ ๋์ด์ ํฌํจ์ด ๋๋ฏ๋ก false๋ฅผ ๋ฆฌํดํ๋ค.
'๐ Problem Solving > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์กฐ์ด์คํฑ / Python (0) | 2021.06.02 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ํ๋ฆฐํฐ / Python (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ํ๊ฒ ๋๋ฒ / Python (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ๋ ๋งต๊ฒ / Python (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ๊ธฐ๋ฅ๊ฐ๋ฐ (0) | 2021.06.02 |