본문 바로가기

코딩테스트6

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.
배열과 해시 대표 문제 풀기 이번 포스트에서는 leetcode에 있는 Array 와 Hashing의 대표 문제들을 풀어보겠습니다. 문제풀이는 편의상 C++로 진행하겠습니다. 1. Containers Duplicates [Easy] Contains Duplicate - 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 containsDuplicate(vector& nums) { // 이전에 나온 값을 저장하기 위해서 HashMap을 준비.. 2022. 10. 30.
[정렬] Merge Sort 개념 정리 및 관련 문제 풀기 이번 포스트에서는 Merge Sort에 대한 개념에 대해 알아보기 관련 문제를 풀어보겠습니다. 개념 정리 Merge Sort는 번역하면 병합 정렬이라고 합니다. Merge Sort는 대표적인 Divide & Conquer 알고리즘입니다. 즉 분할을 해서 작은 사이즈를 먼저 해결하고 나서 합치는 것을 의미합니다. 이 전략이 좋은 이유는 처음부터 많은 양의 비교를 하지 않고 작은 단위부터 정렬된 배열들을 만들어서 합칠때 두 정렬된 배열을 비교하면 되기 때문입니다. 정렬된 배열을 비교하는 것은 일반적인 정렬보다 간단합니다. 왜냐하면 각 배열이 이미 정렬되어 있기 때문에 가장 앞에 있는 것들만 비교하면 됩니다. 예를 들어서 배열 [1, 3, 5, 7] 과 [2, 4, 6, 8] 을 정렬한다고 가정하겠습니다. 두.. 2022. 10. 26.