본문 바로가기

코딩테스트

(55)
[LeetCode] Design Circular Queue(원형 큐 디자인) https://leetcode.com/problems/design-circular-queue/description/ Design Circular Queue - LeetCode Can you solve this real interview question? Design Circular Queue - Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle, and the leetcode.com int Front() : 맨 앞 항목을 가져옵니다. 대기..
[LeetCode] Implement Stack using Queues(큐를 이용한 스택구현) https://leetcode.com/problems/implement-stack-using-queues/description/ Implement Stack using Queues - LeetCode Can you solve this real interview question? Implement Stack using Queues - Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty). Implement the leetcode.com void push(int x)..
[LeetCode] Implement Queue using Stacks(스택을 이용한 큐 구현 ) https://leetcode.com/problems/implement-queue-using-stacks/description/ Implement Queue using Stacks - LeetCode Can you solve this real interview question? Implement Queue using Stacks - Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement t leetcode.com void push(int x)..
백준 2164. 카드2 https://www.acmicpc.net/problem/2164 2164번: 카드2 N장의 카드가 있다. 각각의 카드는 차례로 1부터 N까지의 번호가 붙어 있으며, 1번 카드가 제일 위에, N번 카드가 제일 아래인 상태로 순서대로 카드가 놓여 있다. 이제 다음과 같은 동작을 카드가 www.acmicpc.net 카드가 한 장 남을때까지 반복하는 과정이다. 우선 제일 위에 있는 카드는 버린다. 그 다음 제일 위에 있는 카드는 제일 아래에 있는 카드 밑으로 옮긴다. 그 과정을 반복하면 마지막 한장이 남는데 그 카드의 숫자가 무엇인지 출력하는 문제이다. 이 과정을 queue를 이용해 풀어본다. 파이썬은 리스트가 큐의 역할을 흉내내고 있어 리스트로 풀어본다. import sys nums = int(sys.std..
백준 1874번. 스택수열 https://www.acmicpc.net/problem/1874 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net 문제설명 : ex ) 4 3 6 8 7 5 2 1 을 입력했을때 수열을 만들 수 있는지 수열이 되는지 확인해보는 문제이다. 스택으로 문제를 풀어본다. * 4 : 4까지 스택에 push(총 4번) 해준다. 그럼 스택은 LIFO 이기 때문에 스택의 TOP는 4가 될 것 그리고 찾아야 할 숫자 4 같으면 pop 해준다. ..
Valid Parentheses https://leetcode.com/problems/valid-parentheses/ Valid Parentheses - LeetCode Can you solve this real interview question? Valid Parentheses - Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the sam leetcode.com 문제설명: 문자에 () [] {} 이렇게 제거해나가서 대칭이 모두 맞으면 true 대칭이 ..
[LeetCode] GroupAnagrams https://leetcode.com/problems/group-anagrams/ Group Anagrams - LeetCode Can you solve this real interview question? Group Anagrams - Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase leetcode.com 문제설명 : 문자열이 있을때 같은문자가 들어있는 경우 그룹(리스트)로 묶어 정답 리스트에 추가한다. ..