알고리즘 3

baekjoon. 스택 (10828) [python][Silver IV]

문제 링크 : https://www.acmicpc.net/problem/10828 문제풀이 import sys stack = [] # stack = array : 복잡하게 클래스로 만들 필요 없다 def push(data): stack.append(data) def pop(): if (empty()): print(-1) else: lastIndex = len(stack) -1 print(stack.pop(lastIndex)) # remove (value), pop (index) def size(): print(len(stack)) def empty(): if len(stack) == 0: return 1 else: return 0 def top(): if (empty()): print(-1) else: ..

programmers. 다단계 칫솔 판매

코딩테스트 연습 - 다단계 칫솔 판매 민호는 다단계 조직을 이용하여 칫솔을 판매하고 있습니다. 판매원이 칫솔을 판매하면 그 이익이 피라미드 조직을 타고 조금씩 분배되는 형태의 판매망입니다. 어느정도 판매가 이루어진 후, programmers.co.kr 내가 생각한 알고리즘 내 풀이 (0.5H) import java.util.HashMap; class Solution { static HashMap relationMaps = new HashMap(); static HashMap payMaps = new HashMap(); public int[] solution(String[] enrolls, String[] referrals, String[] sellers, int[] amounts) { int[] answ..

programmers. 행렬 테두리 회전하기

https://programmers.co.kr/learn/courses/30/lessons/77485?language=java# 코딩테스트 연습 - 행렬 테두리 회전하기 6 6 [[2,2,5,4],[3,3,6,6],[5,1,6,3]] [8, 10, 25] 3 3 [[1,1,2,2],[1,2,2,3],[2,1,3,2],[2,2,3,3]] [1, 1, 5, 3] programmers.co.kr 내가 생각한 알고리즘 내 풀이 (2H) import java.util.Arrays; class Solution { int[] dx = {0, 1, 0, -1}; int[] dy = {1, 0, -1, 0}; int[][] origin; int[][] copy; public int[] solution(int rows, ..

반응형