N, M = map(int, input().split()) ls = [] def dfs(cnt, idx): if cnt -1 == M: print(' '.join(map(str,ls))) return for i in range(idx, N+1): ls.append(i) dfs(cnt+1, i) ls.pop() dfs(1,1)
복잡하게 생각하지 않고 그냥 반복되는 행위를 while 문 안에 넣어서 작성했다. from collections import deque # 선언부 num = int(input()) dq = deque([i for i in range(1, num+1)]) # 마지막 하나 남을 때까지 반복문 while (len(dq) > 1): dq.popleft() v = dq.popleft() dq.append(v) print(dq[0]) 원형데크로 작성하면 append 단계가 없어도 될 것 같았지만 연결리스트 구현하고 다음 노드로 넘어가는 코드를 작성하는 것보다 append가 빠를 것 같아서 안함 #데크
순서는 그대로 유지해야하지만 이어져 필요는 없는 부분 문자열이었다. 1. s에서 만들어 질 수 있는 모든 문자열 작성 후 t와 모두 비교 2. t와 s 한 글자씩 비교 일단 위 두 가지의 해결법이 떠올랐다. 근데 2가 간단할 것 같아서 2로 풀이함. import sys input = sys.stdin.readline while True: tc = input().rstrip() if not tc: break s, t = tc.split() status = 'No' idx = 0 for i in range(len(t)): if t[i] == s[idx]: idx+=1 if idx == len(s): status = 'Yes' break print(status) # 그리디 k칸 복호화 -> 사전의 단어 개수만..
input a, b = input().split() 빠르게 입력 받기 import sys // 공백 구분 2개 숫자 N, M = map(int,sys.stdin.readline().split()) // 2차원 리스트 board = [list(map(int,sys.stdin.readline().split())) for _ in range(N)] // 문자열 data = sys.stdin.readline().rstrip() 리스트 출력 대괄호 제거 result = [1,2,3] print(*result)
처음 봤을 때 일년전인가 수업시간에 다룬 보스턴 하우징 데이터가 떠올랐다. 설명을 보니 보스턴 하우징 데이터셋에서 확장시킨 새로운 데이터셋인 모양이다. 새로운 노트북을 생성하고 데이터를 읽어들였다. 오늘 처음 알게된건데 캐글에서는 파일 루트 복사 기능을 제공한다. 👍 wow... 변수가 81개이므로 하나하나 살펴볼 수는 없을 것 같아서 선형회귀분석을 진행했다. 범주형 변수가 존재하여 적합하지 못한다는 오류가 났다. 캐글이 제시한 해결방법은 원-핫 인코딩으로 어제 알아봤던 파이썬 get_dummies 함수가 만들어주는 결과물이 원-핫 인코딩이었다. 선형 회귀분석에 적합하지 않은 변수타입 object가 존재하므로 원핫인코딩을 진행한다. 원핫인코딩을 진행하는 경우와 범주형 변수들을 제외시켜버리는 경우 중 어떤..
Overview of How Kaggle’s Competitions Work 1. Join the Competition Read about the challenge description, accept the Competition Rules and gain access to the competition dataset. 2. Get to Work Download the data, build models on it locally or on Kaggle Kernels (our no-setup, customizable Jupyter Notebooks environment with free GPUs) and generate a prediction file. 3. Make a Submission Upload your..
24. Swap Nodes in Pairs Medium 파이썬 알고리즘 인터뷰 229p Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.) ♬idea while 문, list.next 사용해서 값 바꾸기 1. 그냥 값만 바꾸기 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val ..
234. Palindrome Linked List Easy 파이썬 알고리즘 인터뷰 201p Given the head of a singly linked list, return true if it is a palindrome or false otherwise. ♬idea 빗물 트래핑에서 썼던 투 포인터를 활용할 수 있을 것 같다. 런너를 사용한 역순 연결 리스트 작성을 통해 해결할 수 있을 것 같다. 1. 리스트와 투 포인터 사용 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def isPal..