본문 바로가기

전체 글

Clone Graph (DFS) 이번 문제는 LeetCode의 Queue, Stack 튜토리얼 중 DFS를 다루는 두 번째 문제다. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com BFS와 마찬가지로 DFS 역시 그래프에서 노드부터 노드까지 경로를 찾는 데 사용될 수 있다. 그러나 이 경로가 항상 최단경로라는 보장은 없으며 탐색 순서에 따라, 정확히는 그래프에서 이웃 노드를 참조하는 .. 더보기
Evaluate Reverse Polish Notation (Stack) LeetCode의 Queue, Stack 튜토리얼의 네 번째 문제인 Evaluate Reverse Polish Notation다. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Reverse Polish Notation이 뭔가 했더니 옛날에 자료구조 수업시간에 배웠던 연산식 표기법이었다. 예를 들어 우리 같은 사람들은 보통 1과 2를 더한다고 하면 ".. 더보기
Daily Temperatures (Stack) LeetCode의 Queue, Stack 튜토리얼의 세 번째 문제인 Daily Temperatures다. 프로그래머스의 주식 가격과 비슷한 문제인데 예전에 풀 때는 못 풀었지만 이번에 LeetCode에서 다른 도움 없이 혼자 풀 수 있었기 때문에 프로그래머스의 문제도 풀 수 있을 것이다. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 이번 문제의 조건.. 더보기
Valid Parentheses (Stack) LeetCode의 Queue, Stack 튜토리얼의 두 번째 문제인 Valid Parentheses다. 스택의 대표적인 활용 예제인 괄호 검사 문제인데 학부에서 자료구조 수업 때 스택을 가르칠 때 빼놓지 않고 등장하는 예제다. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제에서 요구하는 사항은 다음과 같다. 괄호로 이루어진 문자열이 주어진다. 해당.. 더보기
Min Stack (Stack) 이번 문제는 LeetCode의 Queue, Stack 튜토리얼에 포함되어 있던 문제로 스택의 기본적인 연산과 추가적으로 요구되는 연산을 수행할 수 있는 스택 자료구조를 직접 구축하여 풀어보는 것이 목적이다. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 재밌는 것은 상위권 풀이를 보면 자바에서 제공하는 Stack 자료구조를 이용해 푼 풀이가 많다는 것.. 더보기
Java를 이용한 Stack 실습 LeetCode의 Queue, Stack 실습 중 Stack 부문을 읽고 작성하는 포스트다. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 자바에서는 Stack이라는 클래스로 Stack, 스택 자료구조를 제공하고 있다. 자료구조를 공부했다면 못 들어봤을 수가 없는 대표적인 Last-In-First-Out 자료구조인 스택은 이전의 Queue와 달리 같은.. 더보기
Perfect Squares (BFS) LeetCode의 Queue 튜토리얼에서 마지막 문제 Perfect Squares다. Account Login - 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 풀이를 보면 주로 DP를 사용하는 것 같은데 아직 거기까진 익숙하지 않기 때문에 그리고 지금은 Queue와 BFS를 풀이하는 중이기 때문에 차치하고 BFS를 활용하여 진행했다. 이번 문제는 풀이를 봐도 이해하는데 시간이 꽤 걸렸는데 다행히 Queue와 BFS를 사용하여 잘 설명된 풀이를 찾을 수 있었다... 더보기
Open the Lock (BFS) 이번 문제 역시 LeetCode의 Stack, Queue 튜토리얼에 있는 'Open the Lock'이라는 문제다. Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com Queue를 활용해서 BFS 방식으로 푸는게 목적이기 때문에 지난번 Number of Islands처럼 DFS같은 방법은 사용하지 않고 진행했다. 이번 문제는 다음과 같다. 0, 1, 2, .. 더보기