본문 바로가기

코딩4

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 Sum 이번에는 배열과 HashMap의 대표적인 문제인 Two Sum 문제를 풀어보겠습니다. 문제 난이도는 쉬운 편에 속하지만 다양한 방법으로 풀 수 있는 방법이 있기 때문에 정확하게 이해하시는 것이 좋습니다. 문제 https://leetcode.com/problems/two-sum/ Two Sum - 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 위 문제는 배열을 순회하는 대표적인 문제입니다. 서로 다른 두 원소를 더해서 target이 나오는 경우를 찾으면 됩니다. .. 2022. 10. 23.