리트코드 5

[알고리즘][Python] LeetCode 225 Implement Stack Using Queues 문제 풀이

문제 출처 : leetcode.com/problems/implement-stack-using-queues/ Implement Stack using Queues - 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 문제 해석 : 큐를 이용해서 스택을 구현하는 문제이다. 문제 풀이 : 큐는 삽입은 뒤에서 삭제는 앞에서 하기 때문에 여기서 신경쓸 것은 Pop 연산이다. 스택은 삭제 또한 뒤에서 하기 때문에 삭제 대상 직전까지 다른 배열에 임시로 저장하고 원하는 값을 제거..

[알고리즘][Python] LeetCode 92 Reverse Linked List 2 문제 풀이

문제 출처 : leetcode.com/problems/reverse-linked-list-ii/ Reverse Linked List II - 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 문제 해석 : 시작점과 끝점이 주어졌을 때 그 구간을 뒤집어서 반화하는 문제이다. 문제 풀이 : 시작점과 끝점 앞과 뒤를 저장해 놓고 그 사이를 뒤집어서 반환하면 된다. ( 이 문제의 풀이는 Python Algorithm Interview 책을 참고 했습니다. ) 풀이 코드 c..

[알고리즘][Python] LeetCode 15 3-Sum 문제 풀이

문제 출처 : leetcode.com/problems/3sum/ 3Sum - 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 문제 해석 : 주어진 리스트에서 3 수의 합이 0이 되는 조합을 모든 찾아 반환하는 문제이다. 문제 풀이 : 브루트포스로 풀이를 진행하면 시간 복잡도에 의해서 정답 처리를 받지 못한다. 따라서 2개의 수를 더하는 것과 같이하면서 그 사이에 수를 선택하는 방법으로 풀이 할 수 있다. ( 아래 풀이는 "파이썬 알고리즘 인터뷰"를 참고 했습니다...

[알고리즘][Python] LeetCode 42 Trapping Rain Water 문제 풀이

문제 출처 : leetcode.com/problems/trapping-rain-water/ Trapping Rain Water - 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 문제 해석 : 빗물이 고이는 총량을 계산하는 문제이다. 문제는 직관적이지만 다양한 접근을 활용할 수 있다. 문제 풀이 : 아래 풀이는 O(n^2)의 브루트포스 풀이법으로 각 원소마다 양쪽의 최댓값을 구해서 작은 부분과의 차를 전체 합에 더해 주는 방식이다. 하지만 이 풀이는 시간제한이 빡..

[알고리즘][Python] LeetCode 5 Longest Palindromic Substring 문제 풀이

문제 출처 : leetcode.com/problems/longest-palindromic-substring/ Longest Palindromic Substring - 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 문제 해석 : 문자열 속에서 가장 긴 팰런드롬을 찾아서 반환하는 문제이다. 문제 풀이 : 이 문제는 투 포인터를 활용하여 풀이 할 수 있다. --> ( 이 문제의 풀이는 파이썬 알고리즘 인터뷰 책의 풀이를 참고 했습니다. ) 풀이 코드 class Sol..