https://school.programmers.co.kr/learn/courses/30/lessons/12905코드function solution(board) { let answer = 0; const r = board.length; const c = board[0].length; const acc = Array.from(new Array(r + 1), () => new Array(c + 1).fill(0)); for (let i = 1; i 누적합을 사용하면 효율적으로 풀 수 있는 문제다. 아래 그림을 보면 어떻게 누적합으로 푼다는건지 좀 더 쉽게 이해할 수 있다.그림에서 빨간 칸이 현재 위치라고 할 때, 현재 위치에서 가능한 최대 정사각형의 크기는 왼쪽, 위쪽, 그리고 대각선 왼쪽 위의 ..
https://school.programmers.co.kr/learn/courses/30/lessons/12909?language=javascript코드function solution(s) { let answer = true; const stack = []; for (const ch of s) { if (ch === "(") { stack.push("("); } else { if (stack.length > 0) { stack.pop(); } else { answer = false; break; } } } if (stack.length > 0) { answer = false; } return ans..
https://leetcode.com/problems/count-and-say/description/코드def countAndSay(n): string = "1" for _ in range(n-1): new_string = "" cnt = 1 prev = string[0] for s in string[1:]: if s == prev: cnt += 1 else: new_string += (str(cnt)+prev) prev = s cnt = 1 new_string += (str(cnt)+p..
https://leetcode.com/problems/rotate-image/description/코드from copy import deepcopyclass Solution: def rotate(self, matrix: List[List[int]]) -> None: n = len(matrix) max_depth = n//2 for depth in range(max_depth+1): length = n-depth*2-1 # 위쪽 저장 top = deepcopy(matrix[depth][depth+1:n-depth]) # 왼 -> 위 for i in range(leng..
https://www.acmicpc.net/problem/1039코드from collections import deque, defaultdictn, k = input().split()n_len = len(n)k = int(k)q = deque([(n, 0)])visited = defaultdict(set)visited[n].add(0)answer = -1while q: now, cnt = q.popleft() if cnt == k: answer = max(int(now), answer) continue for i in range(n_len-1): for j in range(i+1, n_len): if (i == 0 and now[j..
https://www.acmicpc.net/problem/1946코드from heapq import heappop, heappushimport sysinput = sys.stdin.readlinefor _ in range(int(input())): n = int(input()) applicants = [] for _ in range(n): doc, interview = map(int, input().split()) heappush(applicants, (doc, interview)) answer = 1 comp_interview = heappop(applicants)[1] while applicants: now = heappop(app..