일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 참새과
- 솔딱새과
- 딥러닝공부
- SimpleCraft
- 딱다구리과
- 직박구리과
- AI전략게임
- 백로과
- keras
- python3
- 한국의새
- 흰날개해오라기
- 기러기목
- 생일문제
- 오리과
- AI역량평가
- Birthday paradox
- IBK기업은행 인턴
- 참새목
- 계수정렬
- django
- Python
- 가마우지과
- 비둘기과
- ADsP
- 맑은소리 스피치학원
- 비둘기목
- 한국의 새
- structured_array
- 딥러닝 공부
- Today
- Total
목록프로그래밍/코딩테스트 공부 (26)
진박사의 일상
문자열을 앞뒤로 번갈아가며 출력하는 프로그램을 작성하시오. [Java] import java.io.*; class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); while(!input.equals("")){ System.out.print(input.charAt(0)); StringBuffer bf = new StringBuffer(input.substring(1, input.length())); input = bf.reverse().toString();..
그리디 문제로 소개되어 있지만 해시 함수를 이용한 DP 풀이법으로 풀어보았다. from collections import defaultdict class Board: board = [] n = 0 case = defaultdict(list) def __init__(self, n): self.n = n def make_set_by_line(self,line): self.board.append(line) def make_board(self,cur_board,dir): new_board = [] if dir == 0:#북 cur_board = list(map(list,zip(*cur_board))) #print('0',cur_board) for line in cur_board: line = line[::-1]..
def solution(numbers): answer = '' numbers = [str(n) for n in numbers] if numbers.count('0') == len(numbers): return "0" numbers.sort(key=lambda x:x*3, reverse=True) return "".join(numbers) 솔직히 이거 쉽게 생각했는데 1시간 넘게 고민하다 결국 포기하고 답 찾아보고 머리 뽑으며 절규함. 그래도 덕분에 파이썬의 문자열의 숫자 비교 매커니즘에 대해 정확하게 알게 됨.
import heapq def solution(scoville, K): answer = 0 heap = [] for s in scoville: heapq.heappush(heap, s) while True: now_scovile = heapq.heappop(heap) if now_scovile >= K: # 최소값이 K 이상이면 break # 끝 if not heap: #heap이 비었다면 return -1 #K를 만들 수 없었음 else: #힙이 1 이상 남았으면 섞을 수 있음 heapq.heappush(heap, now_scovile + heapq.heappop(heap)*2) #섞은 음식의 스코빌 지수를 계산해 넣기 answer += 1 #섞은 횟수 증가 return answer 17분... 휴 할..
from collections import deque def solution(prices): prices = deque(prices) #deque화 answer = [] while prices: price = prices.popleft() #왼쪽에서 꺼냄 period = 0 for p in prices: if p >= price: #우측 가격이 크거나 같으면 period += 1 #기간 증가 else: #달라지면 period += 1 #1초 증가후 break #기간 끝 answer.append(period) return answer 7분컷~ 이제 슬슬 쉬운 문제에서는 시간이 절약되고 있음.
from collections import defaultdict def solution(genres, plays): answer = [] musics = defaultdict(list) for i in range(len(genres)): musics[genres[i]].append((plays[i], i)) # (재생수,고유번호) set #재생수 총합을 기준으로 내림차순 정렬 playlist_sort = sorted(list(musics.values()), key=lambda x: -sum([play[0] for play in x])) print(playlist_sort) for playlist in playlist_sort: selected = sorted(playlist, key=lambda x: (..