전체 글
-
[Java] Visual Studio code Java 설치Programming/Java 2022. 9. 23. 09:46
1. JDK 설치 https://www.oracle.com/java/technologies/downloads/#java11-windows Download the Latest Java LTS Free Subscribe to Java SE and get the most comprehensive Java support available, with 24/7 global access to the experts. www.oracle.com (JDK 11을 다운 받았는데 VSCode에서는 최신 버전으로 설정하라는 오류 메시지가 떠서 Java 19로 다시 다운로드 하였다.) - Java JDK19 ver - Java JDK11 ver oracle 로그인 하면 바로 jdk가 다운로드됩니다. 다운로드 받은 설치 파일을 실..
-
[c++] smart pointer (unique_ptr, shared_ptr, weak_ptr)Programming/c++ 2022. 9. 22. 11:34
smart pointer C++ 프로그램에서 new 키워드를 사용하여 동적으로 할당받은 메모리는, 반드시 delete 키워드를 사용하여 해제해야 합니다. C++에서는 메모리 누수(memory leak)로부터 프로그램의 안전성을 보장하기 위해 스마트 포인터를 제공하고 있습니다. 스마트 포인터(smart pointer)란 포인터처럼 동작하는 클래스 템플릿으로, 사용이 끝난 메모리를 자동으로 해제해 줍니다. smart pointer 동작 보통 new 키워드를 사용해 기본 포인터(raw pointer)가 실제 메모리를 가리키도록 초기화한 후에, 기본 포인터를 스마트 포인터에 대입하여 사용합니다. 이렇게 정의된 스마트 포인터의 수명이 다하면, 소멸자는 delete 키워드를 사용하여 할당된 메모리를 자동으로 해제합..
-
[c++] std::max_element , std::min_element 함수Programming/c++ 2022. 9. 16. 20:11
std::max_element , std::min_element max_element(), min_element()는 둘다 모든 요소에 접근을 해야 하기 때문에, 모든 STL 컨테이너에 대해서 선형으로 동작한다. 즉, 시간 복잡도가 O(n)이다. std::max_element , std::min_element 함수 정의 // MAX template ForwardIterator max_element (ForwardIterator first, ForwardIterator last); template ForwardIterator max_element (ForwardIterator first, ForwardIterator last, Compare comp); //MIN template ForwardIterato..
-
[Codility] NumberSolitaire c++Coding Test/codility 2022. 9. 16. 19:19
문제 N개의 연속된 정사각형으로 구성된 보드에서 게임이 진행된다. 0번 정사각형의 조약돌을 N-1 정사각형으로 이동시켜야 하는 게임이다. 각 차례마다, 주사위를 던지고 주사위 윗면의 숫자 K를 고려한다. 그런 다음 현재 I에 서 있는 조약돌을 I + K로 이동시킨다. I + K가 존재하지 않으면 유효한 인덱스를 얻을 때까지 주사위를 다시 던진다. 게임이 끝난 후(조약돌이 N-1 로 이동했을 때), 이동한 모든 사각형에 쓰여진 숫자의 합을 구한다. 결론, A[0] → A[N-1] 로 이동할 때의 배열 원소의 최대 합을 구하는 문제이다. 문제 해결 int solution(vector &A) { vector temp(A.size(), -1); temp[0] = A[0]; for(unsigned int i = ..
-
[c++] lower_bound, upper_bound 함수Programming/c++ 2022. 9. 15. 14:36
lower_bound, upper_bound 란? c++에서 이진 탐색으로 원소를 탐색하는 기능을 합니다. lower_bound 찾으려는 target 값보다 같거나 큰 숫자 가 배열 몇 번째에서 처음 등장하는지 찾는 함수 -사용 조건 : 탐색을 진행할 배열 및 벡터는 오름차순으로 정렬되어 있어야 한다. lower_bound 예제 int arr[6] = { 1,2,3,4,5,6 }; int index = lower_bound(arr, arr + 6, 6) - arr; #include #include #include using namespace std; int main() { vector nums = { 1,3,5,6 }; int target = 4; auto a = lower_bound(nums.begin..
-
[LeetCode] 27. Remove Element c++Coding Test/LeetCode 2022. 9. 15. 13:08
문제 설명 Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k el..
-
[LeetCode] 26. Remove Duplicates from Sorted Array c++Coding Test/LeetCode 2022. 9. 15. 10:28
문제 설명 Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elemen..
-
[LeetCode] 1. Two Sum c++Coding Test/LeetCode 2022. 9. 14. 17:59
문제 설명 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. 제한 사항 2