본문 바로가기

전체 글16

Stack 대표 문제 풀기 이번 포스트에서는 Stack과 관련된 문제를 풀어보겠습니다. 풀이는 코드에 직접 적었습니다. 혹시나 궁금하신 부분이 있으시면 댓글로 문의 부탁드립니다. 1. Valid Parentheses Valid Parentheses - 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 Solution { public: bool valid(char & c, stack & st) { if (st.empty()) { return false; } if (c == ').. 2022. 11. 1.
Best Time to Buy and Sell Stock 이번 포스트에서는 Best Time to Buy and Sell Stock 대표 문제를 풀어보겠습니다. 이 시리즈 문제는 Stock을 사고 팔아서 최대 이익을 내는 문제로 다양한 조건이 들어가면서 난이도가 달라집니다. 전반적으로 Sliding Window, Dynamic Programming 기법을 사용하여 풀 수 있습니다. 코딩 테스트 시에 연계해서 나오기 좋은 문제이므로 알아두면 좋습니다. Stock 문제의 가장 기본적인 원리는 팔기 전에 반드시 구매해야 한다는 점입니다. 따라서 Stock을 현재 가지고 있지 않다면 아무리 값이 올라도 판매할 수 없습니다. 또한 거래라고 하면 사고 파는 것이 한 사이클 완료된 경우를 의미합니다. 저는 stock을 사는 경우 거래를 시작한다고 생각하고 문제를 풀었습니다.. 2022. 11. 1.
Sliding Window 대표 문제 풀기 이번 포스트에서는 Sliding Window와 관련된 문제를 풀어보겠습니다. 풀이는 코드에 직접 적었습니다. 혹시나 궁금하신 부분이 있으시면 댓글로 문의 부탁드립니다. 1. Best Time to Buy and Sell Stock Best Time to Buy and Sell Stock - 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 Solution { public: int maxProfit(vector& prices) { // 이전에 나온 최.. 2022. 10. 31.
Two pointers 대표 문제 풀기 이번 포스트에서는 Two pointers 기법으로 풀 수 있는 대표 문제를 풀어보도록 하겠습니다! 문제풀이는 C++로 진행하겠습니다. 1. Valid Palindrome Valid Palindrome - 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 Solution { public: bool isPalindrome(string s) { // 불필요한 문자열을 제거한 최종 결과물을 저장합니다. string filtered = ""; for (aut.. 2022. 10. 31.