[PS] NYPC | 2515. 잃어버린 섬 여행
·
CS/PS
문제당신은 공룡이 살아 숨쉬는, N개의 섬으로 이루어진 섬나라를 여행하게 되었다. 각 섬은 1번부터 N번까지 번호가 매겨져 있으며, 당신은 이 모든 섬을 빠짐없이 방문하려고 한다. 섬들 중 어떤 M개의 쌍에는 선후 관계가 존재한다. 섬 a에서 섬 b로 선후 관계가 존재한다면 반드시 a번 섬을 먼저 방문한 뒤에 섬 b를 방문해야 한다. 각 섬에는 0, 1로 표시되는 두 종류 중 하나의 자외선 위험이 있다. 자외선으로부터 몸을 보호하기 위해 당신은 방호복을 입어야 한다. 같은 종류의 자외선 위험이 있는 섬을 연속으로 방문하는 경우에는 방호복을 갈아 입을 필요가 없지만, 한 종류의 자외선 위험이 있는 섬을 방문한 직후에 다른 종류의 자외선 위험이 있는 섬을 방문하려면 방호복을 갈아 입어야 한다. 처음 방호복을..
[PS] NYPC | 2513. 등차수열
·
CS/PS
문제N개의 항을 가진 수열 A가 있다. 각 항에 11을 더하거나 빼는 연산을 수행할 수 있다. 단, 이 연산은 항 하나에 최대 한 번만 적용 가능하다. 즉, A의 i번째 항의 값이 초기에 x로 주어졌다면, 최종적으로 i번째 항의 값은 연산을 수행하지 않은 경우에는 x, 연산을 수행한 경우에는 x+1 혹은 x−1중 하나가 가능하다. 최소한의 연산으로 수열 A가 공차 1인 등차수열이 되도록 만드는 프로그램을 작성하라. 여기서 공차 1인 등차수열이라 함은, 1 ≤ i N인 모든 정수 i에 대해, i+1번째 항 A_{i+1​}에서 i번째 항 A_i​를 뺀 값이 A_{i+1}−A_i=1임을 뜻한다.예시Example 1.입력5 1 3 4 5 5출력2조건첫 줄에 수열의 길이를 나타내는 정수 N이 주어진다. (1≤N≤..
[PS] Leet | 155. 최솟값 스택
·
CS/PS
문제Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the MinStack class:MinStack() initializes the stack object.void push(int val) pushes the element val onto the stack.void pop() removes the element on the top of the stack.int top() gets the top element of the stack.int getMin() retrieves the minimum element in the stack.You must implement..
[PS] Leet | 146. LRU 캐시
·
CS/PS
문제Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.Implement the LRUCache class:LRUCache(int capacity) Initialize the LRU cache with positive size capacity.int get(int key) Return the value of the key if the key exists, otherwise return -1.void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the ..
정규표현식 (Regular Expression)
·
CS
정규표현식은 특정한 규칙을 가진 문자열의 집합을 표현하는 데 사용하는 형식 언어입니다. 가령, 'E'로 시작하는 단어를 찾거나, 숫자를 제외한 모든 문자열을 찾아내는 등의 경우에 사용됩니다. 아래는 정규표현식을 작성하는 문법에 대해 정리한 표입니다.POSIX 표준기호뜻예시표현가능한 문자열.임의의 한 문자a.baab, abb, acb, ...*임의의 문자열a*bab, aab, aaab, abcb, ...^처음^abc.abca, abcb, abcc, ...$끝.abc$aabc, babc, cabc, ...( )하위식a(bb|cc)dabbd, accd{ }좌측의 문자가 반복a{3}baaab{m,}좌측의 문자가 m회 이상 반복a{3,}baaab, aaaab, ...{m, n}좌측의 문자가 m회 이상, n회 이하..
[PS] Leet | 295. 데이터 스트림에서 중간값 찾기
·
CS/PS
문제The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.For example, for arr = [2,3,4], the median is 3.For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.Implement the MedianFinder class:MedianFinder() initializes the MedianFinder object.void addNum(int num) adds the in..
[PS] Leet | 212. 단어 찾기 II
·
CS/PS
문제Given an m x n board of characters and a list of strings words, return all words on the board.Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.예시Example 1:Input: board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]]..
[PS] Leet | 211. 단어 데이터 추가 및 탐색
·
CS/PS
문제Design a data structure that supports adding new words and finding if a string matches any previously added string.Implement the WordDictionary class:WordDictionary() Initializes the object.void addWord(word) Adds word to the data structure, it can be matched later.bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain..