본문 바로가기

⏳ 알고리즘

(103)
프로그래머스 - LV2. 예상 대진표(2017 팁스타운) 문제 https://programmers.co.kr/learn/courses/30/lessons/12985 코딩테스트 연습 - 예상 대진표 △△ 게임대회가 개최되었습니다. 이 대회는 N명이 참가하고, 토너먼트 형식으로 진행됩니다. N명의 참가자는 각각 1부터 N번을 차례대로 배정받습니다. 그리고, 1번↔2번, 3번↔4번, ... , N-1번↔N programmers.co.kr 코드 1) math이용 import math def solution(n,a,b): exponent_n = int(math.log2(n)) count = 1 while count < exponent_n: a, b = math.ceil(a/2), math.ceil(b/2) if a == b: break else: count += 1 r..
프로그래머스 - LV2. 오픈채팅방(카카오 2019 블라인드 채용) 문제 https://programmers.co.kr/learn/courses/30/lessons/42888 코딩테스트 연습 - 오픈채팅방 오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오 programmers.co.kr 코드 def solution(record): answer = [] dict_nickname = {} for r in record: r = r.split(' ') if r[0] == "Enter" or r[0] == "Change": dict_nickname[r[1]] = r[2] for r in record: r = r.split(' ') if r[0] =..
프로그래머스 - LV1. 신규 아이디 추천(카카오 2021 블라인드 채용) 문제 https://programmers.co.kr/learn/courses/30/lessons/72410# 코딩테스트 연습 - 신규 아이디 추천 카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로 programmers.co.kr 코드 import re def solution(new_id): #1단계 new_id = new_id.lower() #2단계 new_id = re.sub('[^a-z0-9-_.]', '', new_id) #3단계 while '..' in new_id: new_id = new_id.replace("..", ".") #4단계 if new_id[0] ==..
프로그래머스 - LV1. 키패드 누르기(카카오 2020 인턴쉽) 문제 https://programmers.co.kr/learn/courses/30/lessons/67256 코딩테스트 연습 - 키패드 누르기 [1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5] "right" "LRLLLRLLRRL" [7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2] "left" "LRLLRRLLLRR" [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] "right" "LLRLLRLLRL" programmers.co.kr 코드 import numpy as np def solution(numbers, hand): answer = '' key_dict = { 1:(0,0),2:(0,1),3:(0,2), 4:(1,0),5:(1,1),6:(1,2), 7:(2,0),8:(2..
리트코드 - 328. Odd Even Linked List 문제 leetcode.com/problems/odd-even-linked-list/ Odd Even Linked List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 코드 1) 배열 이용 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def o..
리트코드 - 24. Swap Nodes in Pairs 문제 leetcode.com/problems/swap-nodes-in-pairs/ Swap Nodes in Pairs - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 코드 1) 반복 구조 이용 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def ..
리트코드 - 2. Add Two Numbers 문제 leetcode.com/problems/add-two-numbers/ Add Two Numbers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 코드 1) 두 수의 합이 10이상일 경우 carry로 다음 노드에 1전달 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next cl..
리트코드 - 206. Reverse Linked List 문제 leetcode.com/problems/reverse-linked-list/ Reverse Linked List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 코드 1) 연결리스트의 값들을 스택에 순서대로 저장한 뒤, 맨 마지막에 저장된 값부터 차례대로 새로운 연결리스트에 저장 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # se..
리트코드 - 21. Merge Two Sorted Lists 아직 연결리스트 자료구조가 머릿속에서 정리가 잘 안된다. 문제 leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 코드 1) 순차적으로 붙여넣기 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val..
<연결 리스트> 관련 문제 모음 EASY 1. 팰린드롬 연결 리스트 leetcode.com/problems/palindrome-linked-list/ Palindrome Linked List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 > 런너(runner) 기법이란?? 2. 두 정렬 리스트의 병합 leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - LeetCode Level up your coding ski..