본문 바로가기

알고리즘/프로그래머스

(72)
[Python] K번째 수 https://school.programmers.co.kr/learn/courses/30/lessons/42748 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(array, commands): answer = [] for s in commands: n = array[s[0]-1:s[1]] n.sort() n = n[s[2]-1] answer.append(n) return answer
[Python] 영어 끝말잇기 https://school.programmers.co.kr/learn/courses/30/lessons/12981 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # 영어 끝말잇기 def solution(n, words): answer = [] for i in words: if answer == []: answer.append(i) elif not i in answer and answer[-1][-1] == i[0]: answer.append(i) else: break if len(answer) == len(words): return [0,0] else: ..
[Python] 짝지어 제거하기 https://school.programmers.co.kr/learn/courses/30/lessons/12973 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # 짝지어 제거하기 def solution(s): chr = [] for i in s: if chr == []: chr.append(i) elif chr[-1] == i: chr.pop() else: chr.append(i) if chr == []: return 1 else: return 0 solution('ababab')
[Python] 카펫 https://school.programmers.co.kr/learn/courses/30/lessons/42842 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # 카펫 def solution(brown, yellow): answer = [] total = brown + yellow # a * b = total for b in range(1,total+1): if total / b == int(total/b): # total / b = a, 정수여야 한다. a = total / b if a >= b: # a >= b if 2*a + 2*b == brown..
[Python] 최소 직사각형 https://school.programmers.co.kr/learn/courses/30/lessons/86491 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # 최소 직사각형 def solution(sizes): for i in sizes: if i[0] < i[1]: i[0], i[1] = i[1], i[0] width = max(sizes, key=lambda x : x[0])[0] height = max(sizes, key=lambda x : x[1])[1] answer = width * height return answer
[1차] 비밀지도 https://school.programmers.co.kr/learn/courses/30/lessons/17681 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # [1차] 비밀지도 def solution(n, arr1, arr2): arr1_b = [format(x,'b').zfill(n) for x in arr1] arr2_b = [format(x,'b').zfill(n) for x in arr2] answer = [] for a, b in zip(arr1_b, arr2_b): row = '' for i in range(n): if a[i] == '1..
[Python] 시저 암호 https://school.programmers.co.kr/learn/courses/30/lessons/12926 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr # 시저 암호 def solution(s, n): answer = '' for i in s: ascii = ord(i) # 문자를 아스키코드로 변환 ascii += n if i == ' ': # 공백 문자일때 answer += i elif i.isupper(): # 대문자일때 if ascii > 90: ascii -= 26 answer += chr(ascii) else: answer += chr(..
[Python] 다음 큰 숫자 https://school.programmers.co.kr/learn/courses/30/lessons/12911 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(n): n_bin = str(format(n, 'b')) one_cnt = n_bin.count('1') next_num = n+1 while True: next_bin = str(format(next_num, 'b')) next_one_cnt = next_bin.count('1') if one_cnt == next_one_cnt: return next_num else: n..