분류 전체보기

    [프로그래머스] Lv2. 압축

    문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/17684 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 def solution(msg): cnt = 1 arr = [] dict = {} for i in range(65,91): alpha = chr(i) dict[alpha] = cnt cnt += 1 idx = 0 tmp = '' while idx < len(msg): tmp += msg[idx] if tmp in dict: idx += 1 continue else: dict[tm..

    [프로그래머스] Lv2. 더 맵게

    문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/42626 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 import heapq def solution(scoville, K): cnt = 0 heapq.heapify(scoville) while scoville[0] < K: new = heapq.heappop(scoville) + heapq.heappop(scoville)*2 heapq.heappush(scoville,new) cnt += 1 if len(scoville) == 1 ..

    [Spring] MapStruct

    MapStruct란? Entity에서 Dto(Data Transfer Object)로 변환하고자 할때 매핑을 지원하는 라이브러리. 계층간 데이터 교환을 할때 DTO를 변환하는 것을 각 계층에서 하게되면 의존성이 생길 수 있고, 관심사의 분리가 어려워지게 된다. 매핑을 toEntity(),toDto() 와 같은 메서드로 직접 구현해도 되지만, 변환하고자 하는 Dto가 증가할 수록 반복적이고, 불필요한 코드를 작성해야한다. 코드 작성시 실수를 하게 되면, 개발 생산성이 저하한다. 등의 문제가 발생할 수 있다. 환경 설정 build.gradle에 다음과 같이 의존성을 추가한다. implementation 'org.mapstruct:mapstruct:1.4.1.Final' implementation 'org.p..

    [프로그래머스] Lv2. 연속 부분 수열의 합의 개수

    문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/131701 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ✍🏻코드 def solution(elements): arr = [] for j in range(1,len(elements)+1): for i in range(len(elements)): arr.append(sum(elements[0:j])) elements.append(elements.pop(0)) res = set(arr) return len(res) 💡풀이 연속 부분 수열 길이는..

    [프로그래머스] Lv2. k진수에서 소수 개수 구하기

    문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/92335 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ✍🏻코드 def trans(n, k): # n을 k진수로 반환 ret = "" while n > 0: ret += str(n % k) n = n // k return ''.join(reversed(ret)) def isprime(x): # 소수 찾기 if x == 2 or x == 3: return True if x % 2 == 0 or x < 2: return False for i ..

    [프로그래머스] Lv2. 타겟 넘버

    문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 def solution(numbers, target): cnt = 0 size = len(numbers) def dfs(depth,total): if depth == size: if total == target: nonlocal cnt cnt += 1 return dfs(depth+1,total+numbers[depth]) dfs(depth+1,total-numbers[depth..

    [프로그래머스] Lv2. 귤 고르기

    문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/138476?language=python3 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 from collections import Counter def solution(k, tangerine): cnt = 0 c = Counter(tangerine) arr = list(c.items()) arr.sort(reverse=True,key = lambda x : x[1]) for i in arr: if k

    [백준] 1162. 도로포장

    ✍🏻코드 import heapq INF = 98765432109876543210 n,m,k = map(int,input().split()) graph = [[] for _ in range(n+1)] for i in range(m): a,b,c = map(int,input().split()) graph[a].append((b,c)) graph[b].append((a,c)) q = [] distance = [[INF]*(k+1) for _ in range(n+1)] for i in range(k+1): distance[1][i] = 0 heapq.heappush(q,(0,1,0)) while q: dist,now,p = heapq.heappop(q) if dist > distance[now][p]: cont..

    [Spring] DTO를 사용하는 이유

    DTO란? Data Transfer Object의 약자로, 계층간 데이터 교환을 위해 사용하는 객체이다. DTO를 사용하지 않고, Controller에서 View를 뿌릴때 도메인 객체를 Model을 통해 View에 직접 전달할 수 있지만, 민감한 정보 등이 포함되어 노출될 우려가 있기 때문에 Model과 View가 강하게 결합되어 의존성이 생길 수 있다. public class Member { public Long id; public String username; public String email; public String password; //외부에 노출되면 안됨 public String info; //외부에 노출되면 안됨 } @GetMapping public ResponseEntity memberI..

    [프로그래머스] Lv2. 뉴스 클러스터링

    문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/17677 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ✍🏻코드 from collections import Counter def solution(str1, str2): arr1,arr2 = [],[] for i in range(len(str1)-1): if str1[i:i+2].isalpha(): arr1.append(str1[i:i+2].upper()) for i in range(len(str2)-1): if str2[i:i+2].isa..