전체 글52 [leet_code] 915. 랜덤피벗과 호어분할을 이용한 퀵정렬(quick sort) 개선 https://leetcode.com/problems/sort-an-array/description/ Sort an Array - LeetCodeCan you solve this real interview question? Sort an Array - Given an array of integers nums, sort the array in ascending order and return it. You must solve the problem without using any built-in functions in O(nlog(n)) time complexity and with the smallesleetcode.com NLogN의 시간복잡도를 가지는 여러 정렬 알고리즘을 테스트할 수 있는 문제이다.이 중.. 2026. 8. 20. [leet_code] 15. '3Sum' TwoPointer 기법을 활용한 시간복잡도 개선 https://leetcode.com/problems/3sum/description/ 3Sum - LeetCodeCan you solve this real interview question? 3Sum - Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duleetcode.com 세 원소를 더했을 때 Sum이 0이어야한다는 조건속에서 완전탐색이 필수적인 조건이라 생각하여, 작성한 초안 코드는 아래.. 2026. 8. 6. std::weak_ptr를 통한 shared_ptr 생성은 멀티스레드 환경에서 안전한가? 목표멀티스레드 환경에서 weak_ptr의 lock()을 통한 shared_ptr 생성의 결과가유효한 shared_ptr, nullptr 이외에 half-alive 상태일 가능성에 대해 포스팅한다. 1. weak_ptr에 관하여1.1 정의 및 사용목적std::weak_ptr은 소유하지 않는 shared_ptr 이다.shared_ptr로 관리되는 객체에 대해 참조만 할 뿐, use_count를 증가시키지 않는다.이를 통해서 궁극적으로 weak_ptr은 shared_ptr의 순환참조를 예방하는 역할을 수행할 수 있다. 본격적인 예시코드를 읽기전에 shared_ptr로 관리되는 객체는 오직 use_count가 0으로 되었을 때 소멸될 수 있음을 상기한다. struct B;struct A { std::sha.. 2026. 1. 24. Variant 초기화의 중요성 bad_variant_access Std::Variant는 C++ 17에서 지원하는 공용체이다. 공용체란 한 인스턴스에 다양한 타입의 값을 담을 수 있는 구조체를 의미한다. 공용체라면 가장 쉽게 접할 수 있는게 명시적인 Union 일텐데, 현재 Std::Variant는 Value와 함께 저장된 값의 유형을 식별하는 판별자를 관리하기 때문에 공용체를 구현하는데 보다 안정적인 방법으로 선호되고 있다. (기존의 Union의 경우 타입을 판별하지 않기때문에 논리 오류로 이어질 수 있다는 단점이 존재한다.) * Variant의 이용방법은 다음과 같다. https://en.cppreference.com/w/cpp/utility/variant std::variant - cppreference.com template class variant; (sin.. 2022. 6. 3. 이전 1 2 3 4 ··· 13 다음