6_5 - syh39/ProblemSolving GitHub Wiki
K๋ฒ์งธ์
https://programmers.co.kr/learn/courses/30/lessons/42748)
์ถ์ฒ: (๋์ด๋ : 1
ํ์ด์ฌ๋ถ : Y
์ ํ : ์ ๋ ฌ
ํ์ด ๋ฐฉ๋ฒ
def solution(array, commands):
answer = []
for i in commands: // ์ปค๋งจ๋ ๋๋ฉด์
answer.append(answer1(array, i)) // ๊ฐ ์ปค๋ฉ๋์ ๋ต์ answer ๋ฐฐ์ด์ ์ ์ฅ
return answer
def answer1(array, command):
print('answer1')
array = array[command[0]-1:command[1]] // ์๋ฅด๊ธฐ
array.sort() // ์ ๋ ฌ
return array[command[2]-1] // ํด๋น ์ธ๋ฑ์ค ๋ฆฌํด
๋ค๋ฅธ ์ฌ๋์ ํ์ด ๋ฐฉ๋ฒ:
def solution(array, commands):
return list(map(lambda x:sorted(array[x[0]-1:x[1]])[x[2]-1], commands))
// ๋๋ค ํํ์์ผ๋ก ํจ์์ ๋ฐฐ์ด์ ๋งต์ผ๋ก ๋งค์นญํด์ฃผ๊ณ ๊ฐ ๋ต์ ๋ฆฌ์คํธ์ ๋ด์์ ๋ฆฌํด
๊ฐ์ฅ ํฐ ์
https://programmers.co.kr/learn/courses/30/lessons/42746)
์ถ์ฒ: (๋์ด๋ : 2
ํ์ด์ฌ๋ถ : N
์ ํ : ์ ๋ ฌ
ํ์ด ๋ฐฉ๋ฒ
# ๋ค๋ฅธ ์ฌ๋์ ํ์ด ๋ฐฉ๋ฒ ์ฐธ๊ณ
def solution(numbers):
numbers = list(map(str, numbers)) # ์ซ์ ๋ฐฐ์ด์ string์ผ๋ก ๋ณํ
answer = str(int(''.join(sorted(numbers, key=lambda x : x*3, reverse=True)))) # string ์ ์ ๋ถ *3 ํด์ฃผ๊ณ ์ ๋ ฌ(3์๋ฆฌ ๋ค ๋น๊ตํ๊ธฐ ์ํด) ํ ๋น์นธ์์ด join / int ๋ณํ ํ ๋ค์ string์ผ๋ก ๋ณํํด์ฃผ๋ ์ด์ ๋ ์ซ์๊ฐ 000์ผ ๊ฒฝ์ฐ 0์ผ๋ก ํ์ํด์ฃผ๊ธฐ ์ํด
return answer
๊ฒฐ๋ก
ํ์ด ๋ก์ง์ ๋ง์ท์ง๋ง ๊ตฌํ์ ๋ชฐ๋ผ์ ์ฝ๋๋ฅผ ๋ชป์งฐ๋ ๋ฌธ์ ๋ค. ํ์ด์ฌ ์ธ์ด๋ง ์ ์์๋ ๊ตฌํ์ ์ฝ๊ฒ ๋๋ ๊ฒ ๊ฐ๋ค.
์์ ์ฐพ๊ธฐ
https://programmers.co.kr/learn/courses/30/lessons/42839)
์ถ์ฒ: (๋์ด๋ : 2
ํ์ด์ฌ๋ถ : N
์ ํ : ์์ ํ์
ํ์ด ๋ฐฉ๋ฒ
# ๋ค๋ฅธ ์ฌ๋์ ํ์ด ๋ฐฉ๋ฒ ์ฐธ๊ณ
from itertools import permutations
import math
def solution(numbers):
num = [n for n in numbers] # '17' -> ['1', '7']
per = []
for i in range(1, len(numbers)+1):
per += list(permutations(num, i)) # i๊ฐ์ฉ ์์ด์กฐํฉ
new_num = [int(('').join(p)) for p in per] # int ํ์ ์์ด ์กฐํฉ
return countPrimeNumber(set(new_num)) # ์ค๋ณต ์ ๊ฑฐ ํ ํจ์์ ๋๊น
def countPrimeNumber(new_num):
ans = 0
for n in new_num:
checkPrime = True
if(n < 2): # 2๋ณด๋ค ๋ ํฐ ์์ ํํด์
continue
for i in range(2, int(math.sqrt(n))+1): # ์์ด ๊ตฌํ๋ ๋ฐฉ๋ฒ
if n % i == 0:
checkPrime = False
break
if checkPrime: # ์์์ธ ๊ฒฝ์ฐ count++
ans += 1
return ans
๊ฒฐ๋ก
ํ์ด ๋ก์ง์ ๋ง์ท์ง๋ง ๊ตฌํ์ ๋ชฐ๋ผ์ ์ฝ๋๋ฅผ ๋ชป์งฐ๋ ๋ฌธ์ ๋ค. ํ์ด์ฌ ์ธ์ด๋ง ์ ์์๋ ๊ตฌํ์ ์ฝ๊ฒ ๋๋ ๊ฒ ๊ฐ๋ค.