본문 바로가기

전체 글95

프로그래머스 튜플 난이도 Level2 풀이 1. 파이썬의 eval()함수 + 리스트를 사용한 풀이 def solution(s): answer = [] s=s.replace('{','[') s=s.replace('}',']') s=eval(s) s.sort(key=lambda x:len(x)) for num in s: for number in num: if number not in answer: answer.append(number) return answer 2. 파이썬의 eval()함수 + set을 사용한 풀이 def solution(s): answer = [] s=s.replace('{','[') s=s.replace('}',']') s=eval(s) s.sort(key=lambda x:len(x)) for num in.. 2023. 4. 11.
백준 스타트와 링크(14889번) 난이도 실버 II 풀이 1. 재귀함수를 이용하지 않고 combinations함수를 이용해서 풀었다. from itertools import combinations import sys input=sys.stdin.readline N=int(input()) graph=[list(map(int,input().split()))for _ in range(N)] numArr=[i for i in range(N)] checkCase=[] checkCase2=[] result=1000 for case in combinations(numArr,N//2): checkCase.append(case) checkCase2.append(list(set(numArr)-set(case))) for idx in range(len(ch.. 2023. 4. 11.
프로그래머스 귤 고르기 (자바,파이썬 풀이) 난이도 LV2 풀이 파이썬 풀이 from collections import defaultdict def solution(k, tangerine): answer = 0 tangerinedict=defaultdict(int) numbers=[] idx=0 for tan in tangerine: tangerinedict[tan]+=1 for key,value in tangerinedict.items(): numbers.append(value) numbers.sort(reverse=True) for num in numbers: if k0){ k-=tangerineddict.get(keyList.get(i)); answer+=1; i+=1; } return answer; } } 2023. 4. 8.
BOJ 아기상어 (16236번) (자바 / 파이썬 풀이) 난이도 골드 III 풀이 파이썬 풀이 import sys from collections import deque input=sys.stdin.readline N=int(input()) graph=[list(map(int,input().split()))for _ in range(N)] dx=[1,0,-1,0] dy=[0,1,0,-1] startX,startY,sharkSize=0,0,2 cnt=0 path = deque() result=0 def bfs(x,y): tmp=[] visited = [[False for _ in range(N)] for _ in range(N)] distance = [[-1 for _ in range(N)] for _ in range(N)] path.append([x,y]) vi.. 2023. 4. 6.
BOJ 미로탐색 (2178번) 난이도 실버 I 풀이 기본적인 bfs로 풀면 되는 문제였다. import sys from collections import deque input=sys.stdin.readline N,M=map(int,input().split()) path=deque() graph=[list(map(int,input().rstrip())) for _ in range(N)] visited=[[False for _ in range(M)]for _ in range(N)] answer=0 dx=[0,0,-1,1] dy=[-1,1,0,0] path.append([0,0]) while len(path)!=0: curX,curY=path.popleft() for idx in range(4): posX=curX+dx[idx] posY=.. 2023. 4. 6.
프로그래머스 혼자서 하는 틱택토 난이도 Level2 풀이 def isWin(board,x,y): if board[x]=='OOO' or board[x]=='XXX': return True if board[0][y]==board[1][y]==board[2][y]=='O' or board[0][y]==board[1][y]==board[2][y]=='X': return True if x-y==0: if board[0][0]==board[1][1]==board[2][2]=='O' or board[0][0]==board[1][1]==board[2][2]=='X': return True if x+y==2: if board[0][2]==board[1][1]==board[2][0]=='O' or board[0][2]==board[1][1]==boar.. 2023. 4. 5.
JPA에서 동시성 이슈 해결하기 트랜잭션 동시성 이슈 해결하기 이번 프로젝트에서 특정 컨텐츠를 클릭하면 조회수를 +1 해주는 기능이 있었다. 아래 그림에서 보는 것과 같이 유저가 특정 컨텐츠를 클릭하면 해당 컨텐츠의 조회수가 +1이 된다. 해당 프로세스에서 동시성 이슈가 발생할 수 있고 이에 대해서 포스팅 해보고자 한다. 조회수 증가 API의 전체 프로세스 조회수 증가 API의 전체 프로세스는 다음과 같다. 조회수 증가 API의 전체 프로세스 1. 사용자가 특정 컨텐츠를 클릭함. 2. 조회수 증가 API가 애플리케이션 서버에 요청됨 3. 동일한 IP에서 특정 URL을 조회한 기록이 있는지 검사(특정 IP에서 여러번 같은 컨텐츠를 클릭해도 조회수는 1이어야 하므로) 4. 있으면 조회수 +1 로직 처리를 안함 5. 없으면 조회수 +1 로 .. 2023. 4. 5.
BOJ 15787번(기차가 어둠을 헤치고 은하수를) 난이도 실버 II 풀이 이차원 배열을 주어진 조건에 맞게 구현하면 되는 문제였다. 풀이1 풀이1은 리스트를 가지고 구현한 풀이이다. import sys input=sys.stdin.readline N,M=map(int,input().split()) train=[[0 for _ in range(20)]for _ in range(N)] result=0 answer=[] for _ in range(M): command=list(map(int,input().split())) trainIdx=command[1] if len(command)==3: chain=command[2] if command[0]==1: train[trainIdx-1][chain-1]=1 elif command[0]==2: train[trai.. 2023. 4. 5.
프로그래머스 추억 점수(Java/Python) 풀이 파이썬 풀이1 : 리스트와 반복문, 조건문을 사용해서 구현하면 되는 간단한 문제였다. def solution(name, yearning, photo): answer = [] for case in photo: caseSum=0 for people in case: if people in name: idx=name.index(people) caseSum+=yearning[idx] else: pass answer.append(caseSum) return answer 파이썬 풀이2 : zip함수 이용해서도 해결가능하다. def solution(name, yearning, photo): answer = [] year_dict={n:y for n,y in zip(name,yearning)} ans=0 for p.. 2023. 4. 5.