목록알고리즘 문제풀이 (31)
취미가 좋다
https://leetcode.com/problems/implement-trie-prefix-tree/ Implement Trie (Prefix Tree) - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class Trie: def __init__(self): self.dic = {} def insert(self, word): temp = self.dic for c in word: if not temp.get(c): temp[c] = {} te..
https://www.acmicpc.net/problem/14890 14890번: 경사로 첫째 줄에 N (2 ≤ N ≤ 100)과 L (1 ≤ L ≤ N)이 주어진다. 둘째 줄부터 N개의 줄에 지도가 주어진다. 각 칸의 높이는 10보다 작거나 같은 자연수이다. www.acmicpc.net Solution import sys input = sys.stdin.readline def chk(road, L, N): len = 0 pre = road[0] for i, floor in enumerate(road): if floor == pre: len += 1 elif abs(floor-pre) >= 2: return False elif floor > pre: if len < L: return False len =..

https://leetcode.com/problems/course-schedule/ Course Schedule - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution from queue import Queue class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: q = Queue() a2b = {} # a : 조건이 필요한 수업 b2a ..
https://atcoder.jp/contests/abc215/tasks/abc215_d D - Coprime 2 AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online. atcoder.jp 주어진 범위 내에서, 주어진 수들과 모두 서로소(최대공약수가 1)가 되는 값를 찾는 문제이다. Solution N,M = map(int,input().split()) A = list(map(int,input().split())) maxA = max(max(A),M) k = [True] * (maxA+1) isprime = [True] * (maxA+1) prim..
https://atcoder.jp/contests/abc215/tasks/abc215_c C - One More aab aba baa AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online. atcoder.jp Solution from itertools import permutations s, k = input().split(' ') a = set([]) for i in permutations(s, len(s)): a.add(i) a = list(a) a.sort() k = int(k) - 1 print(''.join(a[k])) 문자열 s와 순서 ..
https://leetcode.com/problems/number-of-islands/ Number of Islands - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class Solution: def __init__(self): self.m = 0 self.n = 0 self.grid = [] self.visit = [] def numIslands(self, grid): self.m = len(grid) self.n = len(grid[0]..