Algorithm/Programmers
[Programmers] 코딩 기초 트레이닝 #7
j4ko
2023. 11. 29. 01:37
728x90
반응형
목차
콜라츠 수열
https://school.programmers.co.kr/learn/courses/30/lessons/181919
def solution(n):
answer = []
while n != 1:
answer.append(n)
if n % 2 == 0:
n = int(n / 2)
else:
n = int(3 * n + 1)
answer.append(1)
return answer
가까운 1찾기
https://school.programmers.co.kr/learn/courses/30/lessons/181898
def solution(arr, idx):
for x in range(idx, len(arr)):
if arr[x] == 1:
return x
return -1
특별한 이차원 배열 1
https://school.programmers.co.kr/learn/courses/30/lessons/181833
def solution(n):
grid = []
for idx1 in range(0, n):
grid.append([0 for idx2 in range(n)])
for idx1 in range(0, n):
grid[idx1][idx1] = 1
return grid
ad 제거하기
https://school.programmers.co.kr/learn/courses/30/lessons/181870
def solution(strArr):
answer = []
for idx, value in enumerate(strArr):
if "ad" not in value:
answer.append(value)
return answer
A 강조하기
https://school.programmers.co.kr/learn/courses/30/lessons/181874#
def solution(myString):
myString = myString.replace("a", "A")
for ch in myString:
if ch != "A" and ch.isupper():
myString = myString.replace(ch, ch.lower())
return myString
간단한 계산기
https://school.programmers.co.kr/learn/courses/30/lessons/181865
def solution(binomial):
return eval(binomial)
문자열 잘라서 정렬하기
https://school.programmers.co.kr/learn/courses/30/lessons/181866
def solution(myString):
result = [x for x in myString.split("x") if x]
result.sort(key=lambda x:x)
return result
접미사 배열
https://school.programmers.co.kr/learn/courses/30/lessons/181909
def solution(my_string):
result = []
for x in range(len(my_string) - 1, -1, -1):
if my_string[x: len(my_string)]:
result.append(my_string[x: len(my_string)])
result.sort(key=lambda x:x)
return result
l로 만들기
https://school.programmers.co.kr/learn/courses/30/lessons/181834
def solution(myString):
for x in myString:
if ord(x) < ord("l"):
myString = myString.replace(x, "l")
return myString
수 조작하기 2
https://school.programmers.co.kr/learn/courses/30/lessons/181925
def solution(numLog):
m = {1: "w", -1: "s", +10: "d", -10: "a"}
answer = ""
for idx in range(1, len(numLog)):
gap = numLog[idx] - numLog[idx-1]
answer += m[gap]
return answer
728x90
반응형